annotate src/vim9compile.c @ 23505:bb29b09902d5 v8.2.2295

patch 8.2.2295: incsearch does not detect empty pattern properly Commit: https://github.com/vim/vim/commit/d93a7fc1a98a58f8101ee780d4735079ad99ae35 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jan 4 12:42:13 2021 +0100 patch 8.2.2295: incsearch does not detect empty pattern properly Problem: Incsearch does not detect empty pattern properly. Solution: Return magic state when skipping over a pattern. (Christian Brabandt, closes #7612, closes #6420)
author Bram Moolenaar <Bram@vim.org>
date Mon, 04 Jan 2021 12:45:05 +0100
parents 2247a2ce3630
children 872239543313
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * vim9compile.c: :def and dealing with instructions
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #define USING_FLOAT_STUFF
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 #include "vim.h"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 #if defined(FEAT_EVAL) || defined(PROTO)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 #ifdef VMS
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 # include <float.h>
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 #define DEFINE_VIM9_GLOBALS
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 #include "vim9.h"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
26 // values for ctx_skip
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
27 typedef enum {
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
28 SKIP_NOT, // condition is a constant, produce code
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
29 SKIP_YES, // condition is a constant, do NOT produce code
20933
e2fd5f05342f patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents: 20929
diff changeset
30 SKIP_UNKNOWN // condition is not a constant, produce code
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
31 } skip_T;
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
32
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 * Chain of jump instructions where the end label needs to be set.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 typedef struct endlabel_S endlabel_T;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 struct endlabel_S {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 endlabel_T *el_next; // chain end_label locations
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 int el_end_label; // instruction idx where to set end
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 };
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 * info specific for the scope of :if / elseif / else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 typedef struct {
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
46 int is_seen_else;
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
47 int is_had_return; // every block ends in :return
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 int is_if_label; // instruction idx at IF or ELSEIF
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 endlabel_T *is_end_label; // instructions to set end label
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 } ifscope_T;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 * info specific for the scope of :while
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 typedef struct {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 int ws_top_label; // instruction idx at WHILE
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 endlabel_T *ws_end_label; // instructions to set end
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 } whilescope_T;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 * info specific for the scope of :for
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 typedef struct {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 int fs_top_label; // instruction idx at FOR
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 endlabel_T *fs_end_label; // break instructions
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 } forscope_T;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 * info specific for the scope of :try
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 typedef struct {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 int ts_try_label; // instruction idx at TRY
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 endlabel_T *ts_end_label; // jump to :finally or :endtry
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 int ts_catch_label; // instruction idx of last CATCH
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 int ts_caught_all; // "catch" without argument encountered
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 } tryscope_T;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 typedef enum {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 NO_SCOPE,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 IF_SCOPE,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 WHILE_SCOPE,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 FOR_SCOPE,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 TRY_SCOPE,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 BLOCK_SCOPE
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 } scopetype_T;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 * Info for one scope, pointed to by "ctx_scope".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 typedef struct scope_S scope_T;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 struct scope_S {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 scope_T *se_outer; // scope containing this one
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 scopetype_T se_type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 int se_local_count; // ctx_locals.ga_len before scope
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
95 skip_T se_skip_save; // ctx_skip before the block
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 union {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 ifscope_T se_if;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 whilescope_T se_while;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 forscope_T se_for;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 tryscope_T se_try;
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
101 } se_u;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 };
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 * Entry for "ctx_locals". Used for arguments and local variables.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 typedef struct {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 char_u *lv_name;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 type_T *lv_type;
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
110 int lv_idx; // index of the variable on the stack
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
111 int lv_from_outer; // when TRUE using ctx_outer scope
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
112 int lv_const; // when TRUE cannot be assigned to
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
113 int lv_arg; // when TRUE this is an argument
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 } lvar_T;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 * Context for compiling lines of Vim script.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 * Stores info about the local variables and condition stack.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 struct cctx_S {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 ufunc_T *ctx_ufunc; // current function
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 int ctx_lnum; // line number in current function
20059
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20055
diff changeset
123 char_u *ctx_line_start; // start of current line or NULL
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 garray_T ctx_instr; // generated instructions
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 garray_T ctx_locals; // currently visible local variables
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
127 int ctx_locals_count; // total number of local variables
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22369
diff changeset
129 int ctx_has_closure; // set to one if a closures was created in
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22369
diff changeset
130 // the function
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
131
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 garray_T ctx_imports; // imported items
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133
20907
4eeda7139133 patch 8.2.1005: Vim9: using TRUE/FALSE/MAYBE for ctx_skip is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20899
diff changeset
134 skip_T ctx_skip;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 scope_T *ctx_scope; // current scope, NULL at toplevel
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
136 int ctx_had_return; // last seen statement was "return"
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
138 cctx_T *ctx_outer; // outer scope for lambda or nested
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
139 // function
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
140 int ctx_outer_used; // var in ctx_outer was used
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
141
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 garray_T ctx_type_stack; // type of each item on the stack
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
143 garray_T *ctx_type_list; // list of pointers to allocated types
22691
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
144
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
145 int ctx_has_cmdmod; // ISN_CMDMOD was generated
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 };
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147
23360
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
148 static void delete_def_function_contents(dfunc_T *dfunc, int mark_deleted);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 /*
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
151 * Lookup variable "name" in the local scope and return it in "lvar".
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
152 * "lvar->lv_from_outer" is set accordingly.
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
153 * If "lvar" is NULL only check if the variable can be found.
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
154 * Return FAIL if not found.
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
155 */
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
156 static int
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
157 lookup_local(char_u *name, size_t len, lvar_T *lvar, cctx_T *cctx)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 int idx;
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
160 lvar_T *lvp;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161
19392
5b6f420e7352 patch 8.2.0254: compiler warning for checking size_t to be negative
Bram Moolenaar <Bram@vim.org>
parents: 19388
diff changeset
162 if (len == 0)
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
163 return FAIL;
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
164
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
165 // Find local in current function scope.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 for (idx = 0; idx < cctx->ctx_locals.ga_len; ++idx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 {
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
168 lvp = ((lvar_T *)cctx->ctx_locals.ga_data) + idx;
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
169 if (STRNCMP(name, lvp->lv_name, len) == 0
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
170 && STRLEN(lvp->lv_name) == len)
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
171 {
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
172 if (lvar != NULL)
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
173 {
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
174 *lvar = *lvp;
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
175 lvar->lv_from_outer = FALSE;
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
176 }
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
177 return OK;
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
178 }
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
179 }
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
180
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
181 // Find local in outer function scope.
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
182 if (cctx->ctx_outer != NULL)
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
183 {
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
184 if (lookup_local(name, len, lvar, cctx->ctx_outer) == OK)
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
185 {
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
186 if (lvar != NULL)
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
187 {
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
188 cctx->ctx_outer_used = TRUE;
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
189 lvar->lv_from_outer = TRUE;
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
190 }
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
191 return OK;
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
192 }
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
193 }
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
194
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
195 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 /*
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
199 * Lookup an argument in the current function and an enclosing function.
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
200 * Returns the argument index in "idxp"
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
201 * Returns the argument type in "type"
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
202 * Sets "gen_load_outer" to TRUE if found in outer scope.
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
203 * Returns OK when found, FAIL otherwise.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 static int
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
206 arg_exists(
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
207 char_u *name,
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
208 size_t len,
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
209 int *idxp,
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
210 type_T **type,
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
211 int *gen_load_outer,
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
212 cctx_T *cctx)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 int idx;
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
215 char_u *va_name;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216
19392
5b6f420e7352 patch 8.2.0254: compiler warning for checking size_t to be negative
Bram Moolenaar <Bram@vim.org>
parents: 19388
diff changeset
217 if (len == 0)
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
218 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 for (idx = 0; idx < cctx->ctx_ufunc->uf_args.ga_len; ++idx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 char_u *arg = FUNCARG(cctx->ctx_ufunc, idx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
223 if (STRNCMP(name, arg, len) == 0 && arg[len] == NUL)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
224 {
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
225 if (idxp != NULL)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
226 {
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
227 // Arguments are located above the frame pointer. One further
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
228 // if there is a vararg argument
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
229 *idxp = idx - (cctx->ctx_ufunc->uf_args.ga_len
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
230 + STACK_FRAME_SIZE)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
231 + (cctx->ctx_ufunc->uf_va_name != NULL ? -1 : 0);
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
232
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
233 if (cctx->ctx_ufunc->uf_arg_types != NULL)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
234 *type = cctx->ctx_ufunc->uf_arg_types[idx];
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
235 else
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
236 *type = &t_any;
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
237 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
238 return OK;
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
239 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
240 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
241
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
242 va_name = cctx->ctx_ufunc->uf_va_name;
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
243 if (va_name != NULL
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
244 && STRNCMP(name, va_name, len) == 0 && va_name[len] == NUL)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
245 {
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
246 if (idxp != NULL)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
247 {
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
248 // varargs is always the last argument
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
249 *idxp = -STACK_FRAME_SIZE - 1;
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
250 *type = cctx->ctx_ufunc->uf_va_type;
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
251 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
252 return OK;
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
253 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
254
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
255 if (cctx->ctx_outer != NULL)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
256 {
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
257 // Lookup the name for an argument of the outer function.
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
258 if (arg_exists(name, len, idxp, type, gen_load_outer, cctx->ctx_outer)
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
259 == OK)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
260 {
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
261 *gen_load_outer = TRUE;
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
262 return OK;
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
263 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
264 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
265
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
266 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 /*
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
270 * Lookup a script-local variable in the current script, possibly defined in a
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
271 * block that contains the function "cctx->ctx_ufunc".
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
272 * "cctx" is NULL at the script level.
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
273 * if "len" is <= 0 "name" must be NUL terminated.
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
274 * Return NULL when not found.
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
275 */
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
276 static sallvar_T *
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
277 find_script_var(char_u *name, size_t len, cctx_T *cctx)
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
278 {
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
279 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
280 hashitem_T *hi;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
281 int cc;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
282 sallvar_T *sav;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
283 ufunc_T *ufunc;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
284
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
285 // Find the list of all script variables with the right name.
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
286 if (len > 0)
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
287 {
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
288 cc = name[len];
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
289 name[len] = NUL;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
290 }
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
291 hi = hash_find(&si->sn_all_vars.dv_hashtab, name);
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
292 if (len > 0)
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
293 name[len] = cc;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
294 if (HASHITEM_EMPTY(hi))
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
295 return NULL;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
296
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
297 sav = HI2SAV(hi);
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
298 if (sav->sav_block_id == 0 || cctx == NULL)
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
299 // variable defined in the script scope or not in a function.
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
300 return sav;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
301
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
302 // Go over the variables with this name and find one that was visible
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
303 // from the function.
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
304 ufunc = cctx->ctx_ufunc;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
305 while (sav != NULL)
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
306 {
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
307 int idx;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
308
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
309 // Go over the blocks that this function was defined in. If the
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
310 // variable block ID matches it was visible to the function.
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
311 for (idx = 0; idx < ufunc->uf_block_depth; ++idx)
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
312 if (ufunc->uf_block_ids[idx] == sav->sav_block_id)
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
313 return sav;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
314 sav = sav->sav_next;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
315 }
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
316
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
317 return NULL;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
318 }
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
319
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
320 /*
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 23199
diff changeset
321 * Return TRUE if the script context is Vim9 script.
21931
8e09827f8bac patch 8.2.1515: Vim9: can create s:var in legacy script but cannot unlet
Bram Moolenaar <Bram@vim.org>
parents: 21921
diff changeset
322 */
8e09827f8bac patch 8.2.1515: Vim9: can create s:var in legacy script but cannot unlet
Bram Moolenaar <Bram@vim.org>
parents: 21921
diff changeset
323 static int
8e09827f8bac patch 8.2.1515: Vim9: can create s:var in legacy script but cannot unlet
Bram Moolenaar <Bram@vim.org>
parents: 21921
diff changeset
324 script_is_vim9()
8e09827f8bac patch 8.2.1515: Vim9: can create s:var in legacy script but cannot unlet
Bram Moolenaar <Bram@vim.org>
parents: 21921
diff changeset
325 {
8e09827f8bac patch 8.2.1515: Vim9: can create s:var in legacy script but cannot unlet
Bram Moolenaar <Bram@vim.org>
parents: 21921
diff changeset
326 return SCRIPT_ITEM(current_sctx.sc_sid)->sn_version == SCRIPT_VERSION_VIM9;
8e09827f8bac patch 8.2.1515: Vim9: can create s:var in legacy script but cannot unlet
Bram Moolenaar <Bram@vim.org>
parents: 21921
diff changeset
327 }
8e09827f8bac patch 8.2.1515: Vim9: can create s:var in legacy script but cannot unlet
Bram Moolenaar <Bram@vim.org>
parents: 21921
diff changeset
328
8e09827f8bac patch 8.2.1515: Vim9: can create s:var in legacy script but cannot unlet
Bram Moolenaar <Bram@vim.org>
parents: 21921
diff changeset
329 /*
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
330 * Lookup a variable (without s: prefix) in the current script.
21921
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
331 * If "vim9script" is TRUE the script must be Vim9 script. Used for "var"
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
332 * without "s:".
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
333 * "cctx" is NULL at the script level.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 * Returns OK or FAIL.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 static int
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
337 script_var_exists(char_u *name, size_t len, int vim9script, cctx_T *cctx)
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
338 {
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
339 int is_vim9_script;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340
22381
6fe9536694ff patch 8.2.1739: Vim9: crash when compiling a manually defined function
Bram Moolenaar <Bram@vim.org>
parents: 22371
diff changeset
341 if (current_sctx.sc_sid <= 0)
6fe9536694ff patch 8.2.1739: Vim9: crash when compiling a manually defined function
Bram Moolenaar <Bram@vim.org>
parents: 22371
diff changeset
342 return FAIL;
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
343 is_vim9_script = script_is_vim9();
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
344 if (vim9script && !is_vim9_script)
21921
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
345 return FAIL;
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
346 if (is_vim9_script)
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
347 {
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
348 // Check script variables that were visible where the function was
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
349 // defined.
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
350 if (find_script_var(name, len, cctx) != NULL)
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
351 return OK;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
352 }
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
353 else
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
354 {
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
355 hashtab_T *ht = &SCRIPT_VARS(current_sctx.sc_sid);
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
356 dictitem_T *di;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
357 int cc;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
358
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
359 // Check script variables that are currently visible
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
360 cc = name[len];
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
361 name[len] = NUL;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
362 di = find_var_in_ht(ht, 0, name, TRUE);
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
363 name[len] = cc;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
364 if (di != NULL)
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
365 return OK;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
366 }
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
367
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
368 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370
19623
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
371 /*
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
372 * Check if "p[len]" is already defined, either in script "import_sid" or in
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
373 * compilation context "cctx". "cctx" is NULL at the script level.
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
374 * Does not check the global namespace.
19623
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
375 * Return FAIL and give an error if it defined.
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
376 */
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
377 int
21194
afed2045ffc9 patch 8.2.1148: warning for using int instead of size_t
Bram Moolenaar <Bram@vim.org>
parents: 21188
diff changeset
378 check_defined(char_u *p, size_t len, cctx_T *cctx)
19623
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
379 {
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
380 int c = p[len];
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
381 ufunc_T *ufunc = NULL;
21604
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
382
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
383 p[len] = NUL;
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
384 if (script_var_exists(p, len, FALSE, cctx) == OK
19623
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
385 || (cctx != NULL
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
386 && (lookup_local(p, len, NULL, cctx) == OK
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
387 || arg_exists(p, len, NULL, NULL, NULL, cctx) == OK))
21604
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
388 || find_imported(p, len, cctx) != NULL
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
389 || (ufunc = find_func_even_dead(p, FALSE, cctx)) != NULL)
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
390 {
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
391 // A local or script-local function can shadow a global function.
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
392 if (ufunc == NULL || !func_is_global(ufunc)
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
393 || (p[0] == 'g' && p[1] == ':'))
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
394 {
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
395 p[len] = c;
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
396 semsg(_(e_name_already_defined_str), p);
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
397 return FAIL;
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
398 }
19623
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
399 }
21604
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
400 p[len] = c;
19623
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
401 return OK;
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
402 }
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
403
21383
f25d007f90ac patch 8.2.1242: Vim9: no error if calling a function with wrong type
Bram Moolenaar <Bram@vim.org>
parents: 21371
diff changeset
404
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 /////////////////////////////////////////////////////////////////////
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 // Following generate_ functions expect the caller to call ga_grow().
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407
20907
4eeda7139133 patch 8.2.1005: Vim9: using TRUE/FALSE/MAYBE for ctx_skip is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20899
diff changeset
408 #define RETURN_NULL_IF_SKIP(cctx) if (cctx->ctx_skip == SKIP_YES) return NULL
4eeda7139133 patch 8.2.1005: Vim9: using TRUE/FALSE/MAYBE for ctx_skip is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20899
diff changeset
409 #define RETURN_OK_IF_SKIP(cctx) if (cctx->ctx_skip == SKIP_YES) return OK
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
410
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 * Generate an instruction without arguments.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 * Returns a pointer to the new instruction, NULL if failed.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 static isn_T *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 generate_instr(cctx_T *cctx, isntype_T isn_type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 garray_T *instr = &cctx->ctx_instr;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
421 RETURN_NULL_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 if (ga_grow(instr, 1) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 isn = ((isn_T *)instr->ga_data) + instr->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 isn->isn_type = isn_type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 isn->isn_lnum = cctx->ctx_lnum + 1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 ++instr->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 return isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 * Generate an instruction without arguments.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 * "drop" will be removed from the stack.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 * Returns a pointer to the new instruction, NULL if failed.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 static isn_T *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 generate_instr_drop(cctx_T *cctx, isntype_T isn_type, int drop)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 garray_T *stack = &cctx->ctx_type_stack;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
442 RETURN_NULL_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 stack->ga_len -= drop;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 return generate_instr(cctx, isn_type);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 * Generate instruction "isn_type" and put "type" on the type stack.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 static isn_T *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 generate_instr_type(cctx_T *cctx, isntype_T isn_type, type_T *type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 garray_T *stack = &cctx->ctx_type_stack;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 if ((isn = generate_instr(cctx, isn_type)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 if (ga_grow(stack, 1) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 return NULL;
21473
8bcd1ee2630b patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
461 ((type_T **)stack->ga_data)[stack->ga_len] = type == NULL ? &t_any : type;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 ++stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 return isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 * If type at "offset" isn't already VAR_STRING then generate ISN_2STRING.
21771
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
469 * But only for simple types.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 may_generate_2STRING(int offset, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 isn_T *isn;
21771
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
475 isntype_T isntype = ISN_2STRING;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 garray_T *stack = &cctx->ctx_type_stack;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 type_T **type = ((type_T **)stack->ga_data) + stack->ga_len + offset;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478
21771
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
479 switch ((*type)->tt_type)
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
480 {
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
481 // nothing to be done
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
482 case VAR_STRING: return OK;
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
483
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
484 // conversion possible
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
485 case VAR_SPECIAL:
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
486 case VAR_BOOL:
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
487 case VAR_NUMBER:
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
488 case VAR_FLOAT:
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
489 break;
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
490
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
491 // conversion possible (with runtime check)
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
492 case VAR_ANY:
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
493 case VAR_UNKNOWN:
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
494 isntype = ISN_2STRING_ANY;
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
495 break;
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
496
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
497 // conversion not possible
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
498 case VAR_VOID:
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
499 case VAR_BLOB:
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
500 case VAR_FUNC:
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
501 case VAR_PARTIAL:
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
502 case VAR_LIST:
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
503 case VAR_DICT:
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
504 case VAR_JOB:
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
505 case VAR_CHANNEL:
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
506 to_string_error((*type)->tt_type);
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
507 return FAIL;
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
508 }
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
509
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 *type = &t_string;
21771
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
511 if ((isn = generate_instr(cctx, isntype)) == NULL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 isn->isn_arg.number = offset;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 check_number_or_float(vartype_T type1, vartype_T type2, char_u *op)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 {
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
521 if (!((type1 == VAR_NUMBER || type1 == VAR_FLOAT || type1 == VAR_ANY)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 && (type2 == VAR_NUMBER || type2 == VAR_FLOAT
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
523 || type2 == VAR_ANY)))
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 if (*op == '+')
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
526 emsg(_(e_wrong_argument_type_for_plus));
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 else
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
528 semsg(_(e_char_requires_number_or_float_arguments), *op);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
534 static int
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
535 generate_add_instr(
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
536 cctx_T *cctx,
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
537 vartype_T vartype,
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
538 type_T *type1,
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
539 type_T *type2)
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
540 {
23199
59f31d2eb4cf patch 8.2.2145: Vim9: concatenating lists does not adjust type of result
Bram Moolenaar <Bram@vim.org>
parents: 23195
diff changeset
541 garray_T *stack = &cctx->ctx_type_stack;
59f31d2eb4cf patch 8.2.2145: Vim9: concatenating lists does not adjust type of result
Bram Moolenaar <Bram@vim.org>
parents: 23195
diff changeset
542 isn_T *isn = generate_instr_drop(cctx,
59f31d2eb4cf patch 8.2.2145: Vim9: concatenating lists does not adjust type of result
Bram Moolenaar <Bram@vim.org>
parents: 23195
diff changeset
543 vartype == VAR_NUMBER ? ISN_OPNR
59f31d2eb4cf patch 8.2.2145: Vim9: concatenating lists does not adjust type of result
Bram Moolenaar <Bram@vim.org>
parents: 23195
diff changeset
544 : vartype == VAR_LIST ? ISN_ADDLIST
59f31d2eb4cf patch 8.2.2145: Vim9: concatenating lists does not adjust type of result
Bram Moolenaar <Bram@vim.org>
parents: 23195
diff changeset
545 : vartype == VAR_BLOB ? ISN_ADDBLOB
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
546 #ifdef FEAT_FLOAT
23199
59f31d2eb4cf patch 8.2.2145: Vim9: concatenating lists does not adjust type of result
Bram Moolenaar <Bram@vim.org>
parents: 23195
diff changeset
547 : vartype == VAR_FLOAT ? ISN_OPFLOAT
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
548 #endif
23199
59f31d2eb4cf patch 8.2.2145: Vim9: concatenating lists does not adjust type of result
Bram Moolenaar <Bram@vim.org>
parents: 23195
diff changeset
549 : ISN_OPANY, 1);
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
550
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
551 if (vartype != VAR_LIST && vartype != VAR_BLOB
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
552 && type1->tt_type != VAR_ANY
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
553 && type2->tt_type != VAR_ANY
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
554 && check_number_or_float(
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
555 type1->tt_type, type2->tt_type, (char_u *)"+") == FAIL)
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
556 return FAIL;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
557
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
558 if (isn != NULL)
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
559 isn->isn_arg.op.op_type = EXPR_ADD;
23199
59f31d2eb4cf patch 8.2.2145: Vim9: concatenating lists does not adjust type of result
Bram Moolenaar <Bram@vim.org>
parents: 23195
diff changeset
560
59f31d2eb4cf patch 8.2.2145: Vim9: concatenating lists does not adjust type of result
Bram Moolenaar <Bram@vim.org>
parents: 23195
diff changeset
561 // When concatenating two lists with different member types the member type
59f31d2eb4cf patch 8.2.2145: Vim9: concatenating lists does not adjust type of result
Bram Moolenaar <Bram@vim.org>
parents: 23195
diff changeset
562 // becomes "any".
59f31d2eb4cf patch 8.2.2145: Vim9: concatenating lists does not adjust type of result
Bram Moolenaar <Bram@vim.org>
parents: 23195
diff changeset
563 if (vartype == VAR_LIST
59f31d2eb4cf patch 8.2.2145: Vim9: concatenating lists does not adjust type of result
Bram Moolenaar <Bram@vim.org>
parents: 23195
diff changeset
564 && type1->tt_type == VAR_LIST && type2->tt_type == VAR_LIST
59f31d2eb4cf patch 8.2.2145: Vim9: concatenating lists does not adjust type of result
Bram Moolenaar <Bram@vim.org>
parents: 23195
diff changeset
565 && type1->tt_member != type2->tt_member)
59f31d2eb4cf patch 8.2.2145: Vim9: concatenating lists does not adjust type of result
Bram Moolenaar <Bram@vim.org>
parents: 23195
diff changeset
566 (((type_T **)stack->ga_data)[stack->ga_len - 1]) = &t_list_any;
59f31d2eb4cf patch 8.2.2145: Vim9: concatenating lists does not adjust type of result
Bram Moolenaar <Bram@vim.org>
parents: 23195
diff changeset
567
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
568 return isn == NULL ? FAIL : OK;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
569 }
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
570
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
571 /*
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
572 * Get the type to use for an instruction for an operation on "type1" and
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
573 * "type2". If they are matching use a type-specific instruction. Otherwise
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
574 * fall back to runtime type checking.
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
575 */
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
576 static vartype_T
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
577 operator_type(type_T *type1, type_T *type2)
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
578 {
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
579 if (type1->tt_type == type2->tt_type
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
580 && (type1->tt_type == VAR_NUMBER
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
581 || type1->tt_type == VAR_LIST
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
582 #ifdef FEAT_FLOAT
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
583 || type1->tt_type == VAR_FLOAT
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
584 #endif
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
585 || type1->tt_type == VAR_BLOB))
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
586 return type1->tt_type;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
587 return VAR_ANY;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
588 }
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
589
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 * Generate an instruction with two arguments. The instruction depends on the
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 * type of the arguments.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 generate_two_op(cctx_T *cctx, char_u *op)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 garray_T *stack = &cctx->ctx_type_stack;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 type_T *type1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 type_T *type2;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 vartype_T vartype;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
603 RETURN_OK_IF_SKIP(cctx);
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
604
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
605 // Get the known type of the two items on the stack.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 type1 = ((type_T **)stack->ga_data)[stack->ga_len - 2];
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 type2 = ((type_T **)stack->ga_data)[stack->ga_len - 1];
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
608 vartype = operator_type(type1, type2);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 switch (*op)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 {
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
612 case '+':
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
613 if (generate_add_instr(cctx, vartype, type1, type2) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 case '-':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 case '*':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 case '/': if (check_number_or_float(type1->tt_type, type2->tt_type,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 op) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 if (vartype == VAR_NUMBER)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 isn = generate_instr_drop(cctx, ISN_OPNR, 1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 else if (vartype == VAR_FLOAT)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 isn = generate_instr_drop(cctx, ISN_OPFLOAT, 1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 isn = generate_instr_drop(cctx, ISN_OPANY, 1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 if (isn != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 isn->isn_arg.op.op_type = *op == '*'
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 ? EXPR_MULT : *op == '/'? EXPR_DIV : EXPR_SUB;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
635 case '%': if ((type1->tt_type != VAR_ANY
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 && type1->tt_type != VAR_NUMBER)
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
637 || (type2->tt_type != VAR_ANY
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 && type2->tt_type != VAR_NUMBER))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
640 emsg(_(e_percent_requires_number_arguments));
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 isn = generate_instr_drop(cctx,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 vartype == VAR_NUMBER ? ISN_OPNR : ISN_OPANY, 1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 if (isn != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 isn->isn_arg.op.op_type = EXPR_REM;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 // correct type of result
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
651 if (vartype == VAR_ANY)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 type_T *type = &t_any;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 // float+number and number+float results in float
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 if ((type1->tt_type == VAR_NUMBER || type1->tt_type == VAR_FLOAT)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 && (type2->tt_type == VAR_NUMBER || type2->tt_type == VAR_FLOAT))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 type = &t_float;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 ((type_T **)stack->ga_data)[stack->ga_len - 1] = type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 /*
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
668 * Get the instruction to use for comparing "type1" with "type2"
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
669 * Return ISN_DROP when failed.
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
670 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
671 static isntype_T
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
672 get_compare_isn(exptype_T exptype, vartype_T type1, vartype_T type2)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 isntype_T isntype = ISN_DROP;
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
675
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
676 if (type1 == VAR_UNKNOWN)
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
677 type1 = VAR_ANY;
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
678 if (type2 == VAR_UNKNOWN)
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
679 type2 = VAR_ANY;
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
680
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 if (type1 == type2)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 switch (type1)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 case VAR_BOOL: isntype = ISN_COMPAREBOOL; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 case VAR_SPECIAL: isntype = ISN_COMPARESPECIAL; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 case VAR_NUMBER: isntype = ISN_COMPARENR; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 case VAR_FLOAT: isntype = ISN_COMPAREFLOAT; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 case VAR_STRING: isntype = ISN_COMPARESTRING; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 case VAR_BLOB: isntype = ISN_COMPAREBLOB; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 case VAR_LIST: isntype = ISN_COMPARELIST; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 case VAR_DICT: isntype = ISN_COMPAREDICT; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 case VAR_FUNC: isntype = ISN_COMPAREFUNC; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 default: isntype = ISN_COMPAREANY; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 }
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
697 else if (type1 == VAR_ANY || type2 == VAR_ANY
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 || ((type1 == VAR_NUMBER || type1 == VAR_FLOAT)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 && (type2 == VAR_NUMBER || type2 ==VAR_FLOAT)))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 isntype = ISN_COMPAREANY;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 if ((exptype == EXPR_IS || exptype == EXPR_ISNOT)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 && (isntype == ISN_COMPAREBOOL
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 || isntype == ISN_COMPARESPECIAL
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 || isntype == ISN_COMPARENR
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 || isntype == ISN_COMPAREFLOAT))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
708 semsg(_(e_cannot_use_str_with_str),
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 exptype == EXPR_IS ? "is" : "isnot" , vartype_name(type1));
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
710 return ISN_DROP;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 if (isntype == ISN_DROP
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 || ((exptype != EXPR_EQUAL && exptype != EXPR_NEQUAL
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 && (type1 == VAR_BOOL || type1 == VAR_SPECIAL
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 || type2 == VAR_BOOL || type2 == VAR_SPECIAL)))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 || ((exptype != EXPR_EQUAL && exptype != EXPR_NEQUAL
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 && exptype != EXPR_IS && exptype != EXPR_ISNOT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 && (type1 == VAR_BLOB || type2 == VAR_BLOB
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 || type1 == VAR_LIST || type2 == VAR_LIST))))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
721 semsg(_(e_cannot_compare_str_with_str),
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 vartype_name(type1), vartype_name(type2));
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
723 return ISN_DROP;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
724 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
725 return isntype;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
726 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
727
21251
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
728 int
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
729 check_compare_types(exptype_T type, typval_T *tv1, typval_T *tv2)
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
730 {
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
731 if (get_compare_isn(type, tv1->v_type, tv2->v_type) == ISN_DROP)
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
732 return FAIL;
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
733 return OK;
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
734 }
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
735
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
736 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
737 * Generate an ISN_COMPARE* instruction with a boolean result.
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
738 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
739 static int
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
740 generate_COMPARE(cctx_T *cctx, exptype_T exptype, int ic)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
741 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
742 isntype_T isntype;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
743 isn_T *isn;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
744 garray_T *stack = &cctx->ctx_type_stack;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
745 vartype_T type1;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
746 vartype_T type2;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
747
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
748 RETURN_OK_IF_SKIP(cctx);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
749
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
750 // Get the known type of the two items on the stack. If they are matching
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
751 // use a type-specific instruction. Otherwise fall back to runtime type
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
752 // checking.
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
753 type1 = ((type_T **)stack->ga_data)[stack->ga_len - 2]->tt_type;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
754 type2 = ((type_T **)stack->ga_data)[stack->ga_len - 1]->tt_type;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
755 isntype = get_compare_isn(exptype, type1, type2);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
756 if (isntype == ISN_DROP)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 if ((isn = generate_instr(cctx, isntype)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 isn->isn_arg.op.op_type = exptype;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 isn->isn_arg.op.op_ic = ic;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 // takes two arguments, puts one bool back
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 if (stack->ga_len >= 2)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 --stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 ((type_T **)stack->ga_data)[stack->ga_len - 1] = &t_bool;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 * Generate an ISN_2BOOL instruction.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 generate_2BOOL(cctx_T *cctx, int invert)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 garray_T *stack = &cctx->ctx_type_stack;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
783 RETURN_OK_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 if ((isn = generate_instr(cctx, ISN_2BOOL)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 isn->isn_arg.number = invert;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 // type becomes bool
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 ((type_T **)stack->ga_data)[stack->ga_len - 1] = &t_bool;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
794 /*
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
795 * Generate an ISN_COND2BOOL instruction.
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
796 */
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
797 static int
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
798 generate_COND2BOOL(cctx_T *cctx)
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
799 {
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
800 isn_T *isn;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
801 garray_T *stack = &cctx->ctx_type_stack;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
802
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
803 RETURN_OK_IF_SKIP(cctx);
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
804 if ((isn = generate_instr(cctx, ISN_COND2BOOL)) == NULL)
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
805 return FAIL;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
806
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
807 // type becomes bool
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
808 ((type_T **)stack->ga_data)[stack->ga_len - 1] = &t_bool;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
809
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
810 return OK;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
811 }
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
812
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 static int
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
814 generate_TYPECHECK(
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
815 cctx_T *cctx,
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
816 type_T *expected,
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
817 int offset)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 garray_T *stack = &cctx->ctx_type_stack;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
822 RETURN_OK_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 if ((isn = generate_instr(cctx, ISN_CHECKTYPE)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 return FAIL;
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
825 isn->isn_arg.type.ct_type = alloc_type(expected);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 isn->isn_arg.type.ct_off = offset;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
828 // type becomes expected
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
829 ((type_T **)stack->ga_data)[stack->ga_len + offset] = expected;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833
23458
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
834 static int
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
835 generate_SETTYPE(
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
836 cctx_T *cctx,
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
837 type_T *expected)
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
838 {
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
839 isn_T *isn;
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
840
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
841 RETURN_OK_IF_SKIP(cctx);
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
842 if ((isn = generate_instr(cctx, ISN_SETTYPE)) == NULL)
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
843 return FAIL;
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
844 isn->isn_arg.type.ct_type = alloc_type(expected);
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
845 return OK;
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
846 }
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
847
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 /*
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
849 * Return TRUE if "actual" could be "expected" and a runtime typecheck is to be
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
850 * used. Return FALSE if the types will never match.
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
851 */
22898
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22860
diff changeset
852 int
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
853 use_typecheck(type_T *actual, type_T *expected)
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
854 {
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
855 if (actual->tt_type == VAR_ANY
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
856 || actual->tt_type == VAR_UNKNOWN
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
857 || (actual->tt_type == VAR_FUNC
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
858 && (expected->tt_type == VAR_FUNC
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
859 || expected->tt_type == VAR_PARTIAL)
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
860 && (actual->tt_member == &t_any || actual->tt_argcount < 0)))
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
861 return TRUE;
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
862 if ((actual->tt_type == VAR_LIST || actual->tt_type == VAR_DICT)
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
863 && actual->tt_type == expected->tt_type)
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
864 // This takes care of a nested list or dict.
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
865 return use_typecheck(actual->tt_member, expected->tt_member);
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
866 return FALSE;
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
867 }
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
868
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
869 /*
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
870 * Check that
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
871 * - "actual" matches "expected" type or
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
872 * - "actual" is a type that can be "expected" type: add a runtime check; or
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
873 * - return FAIL.
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
874 * If "actual_is_const" is TRUE then the type won't change at runtime, do not
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
875 * generate a TYPECHECK.
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
876 */
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
877 static int
21265
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21255
diff changeset
878 need_type(
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21255
diff changeset
879 type_T *actual,
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21255
diff changeset
880 type_T *expected,
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21255
diff changeset
881 int offset,
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21255
diff changeset
882 cctx_T *cctx,
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
883 int silent,
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
884 int actual_is_const)
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
885 {
22196
d835f2fdfcfc patch 8.2.1647: Vim9: result of expression with && and || is not a bool
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
886 if (expected == &t_bool && actual != &t_bool
d835f2fdfcfc patch 8.2.1647: Vim9: result of expression with && and || is not a bool
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
887 && (actual->tt_flags & TTFLAG_BOOL_OK))
d835f2fdfcfc patch 8.2.1647: Vim9: result of expression with && and || is not a bool
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
888 {
d835f2fdfcfc patch 8.2.1647: Vim9: result of expression with && and || is not a bool
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
889 // Using "0", "1" or the result of an expression with "&&" or "||" as a
d835f2fdfcfc patch 8.2.1647: Vim9: result of expression with && and || is not a bool
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
890 // boolean is OK but requires a conversion.
d835f2fdfcfc patch 8.2.1647: Vim9: result of expression with && and || is not a bool
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
891 generate_2BOOL(cctx, FALSE);
d835f2fdfcfc patch 8.2.1647: Vim9: result of expression with && and || is not a bool
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
892 return OK;
d835f2fdfcfc patch 8.2.1647: Vim9: result of expression with && and || is not a bool
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
893 }
d835f2fdfcfc patch 8.2.1647: Vim9: result of expression with && and || is not a bool
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
894
22004
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
895 if (check_type(expected, actual, FALSE, 0) == OK)
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
896 return OK;
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
897
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
898 // If the actual type can be the expected type add a runtime check.
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
899 // If it's a constant a runtime check makes no sense.
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
900 if (!actual_is_const && use_typecheck(actual, expected))
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
901 {
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
902 generate_TYPECHECK(cctx, expected, offset);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
903 return OK;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
904 }
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
905
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
906 if (!silent)
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
907 type_mismatch(expected, actual);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
908 return FAIL;
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
909 }
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
910
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
911 /*
22860
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
912 * Check that the top of the type stack has a type that can be used as a
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
913 * condition. Give an error and return FAIL if not.
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
914 */
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
915 static int
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
916 bool_on_stack(cctx_T *cctx)
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
917 {
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
918 garray_T *stack = &cctx->ctx_type_stack;
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
919 type_T *type;
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
920
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
921 type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
922 if (type == &t_bool)
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
923 return OK;
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
924
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
925 if (type == &t_any || type == &t_number)
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
926 // Number 0 and 1 are OK to use as a bool. "any" could also be a bool.
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
927 // This requires a runtime type check.
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
928 return generate_COND2BOOL(cctx);
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
929
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
930 return need_type(type, &t_bool, -1, cctx, FALSE, FALSE);
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
931 }
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
932
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
933 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 * Generate an ISN_PUSHNR instruction.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 generate_PUSHNR(cctx_T *cctx, varnumber_T number)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 isn_T *isn;
22184
2463b3d89ce2 patch 8.2.1641: Vim9: cannot use 0 or 1 where a bool is expected
Bram Moolenaar <Bram@vim.org>
parents: 22176
diff changeset
940 garray_T *stack = &cctx->ctx_type_stack;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
942 RETURN_OK_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 if ((isn = generate_instr_type(cctx, ISN_PUSHNR, &t_number)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 isn->isn_arg.number = number;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946
22184
2463b3d89ce2 patch 8.2.1641: Vim9: cannot use 0 or 1 where a bool is expected
Bram Moolenaar <Bram@vim.org>
parents: 22176
diff changeset
947 if (number == 0 || number == 1)
2463b3d89ce2 patch 8.2.1641: Vim9: cannot use 0 or 1 where a bool is expected
Bram Moolenaar <Bram@vim.org>
parents: 22176
diff changeset
948 // A 0 or 1 number can also be used as a bool.
23334
4b4f695e9cd1 patch 8.2.2210: Vim9: allocating a type to set TTFLAG_BOOL_OK
Bram Moolenaar <Bram@vim.org>
parents: 23332
diff changeset
949 ((type_T **)stack->ga_data)[stack->ga_len - 1] = &t_number_bool;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 * Generate an ISN_PUSHBOOL instruction.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 generate_PUSHBOOL(cctx_T *cctx, varnumber_T number)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
961 RETURN_OK_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 if ((isn = generate_instr_type(cctx, ISN_PUSHBOOL, &t_bool)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 isn->isn_arg.number = number;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 * Generate an ISN_PUSHSPEC instruction.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 generate_PUSHSPEC(cctx_T *cctx, varnumber_T number)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
977 RETURN_OK_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 if ((isn = generate_instr_type(cctx, ISN_PUSHSPEC, &t_special)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 isn->isn_arg.number = number;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 * Generate an ISN_PUSHF instruction.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 generate_PUSHF(cctx_T *cctx, float_T fnumber)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
994 RETURN_OK_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 if ((isn = generate_instr_type(cctx, ISN_PUSHF, &t_float)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 isn->isn_arg.fnumber = fnumber;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 * Generate an ISN_PUSHS instruction.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 * Consumes "str".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 generate_PUSHS(cctx_T *cctx, char_u *str)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011
23473
ad83c0ff34c0 patch 8.2.2279: Vim9: memory leak with catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23458
diff changeset
1012 if (cctx->ctx_skip == SKIP_YES)
ad83c0ff34c0 patch 8.2.2279: Vim9: memory leak with catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23458
diff changeset
1013 {
ad83c0ff34c0 patch 8.2.2279: Vim9: memory leak with catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23458
diff changeset
1014 vim_free(str);
ad83c0ff34c0 patch 8.2.2279: Vim9: memory leak with catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23458
diff changeset
1015 return OK;
ad83c0ff34c0 patch 8.2.2279: Vim9: memory leak with catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23458
diff changeset
1016 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 if ((isn = generate_instr_type(cctx, ISN_PUSHS, &t_string)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 isn->isn_arg.string = str;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 /*
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1025 * Generate an ISN_PUSHCHANNEL instruction.
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1026 * Consumes "channel".
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1027 */
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1028 static int
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1029 generate_PUSHCHANNEL(cctx_T *cctx, channel_T *channel)
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1030 {
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1031 isn_T *isn;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1032
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1033 RETURN_OK_IF_SKIP(cctx);
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1034 if ((isn = generate_instr_type(cctx, ISN_PUSHCHANNEL, &t_channel)) == NULL)
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1035 return FAIL;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1036 isn->isn_arg.channel = channel;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1037
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1038 return OK;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1039 }
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1040
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1041 /*
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1042 * Generate an ISN_PUSHJOB instruction.
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1043 * Consumes "job".
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1044 */
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1045 static int
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1046 generate_PUSHJOB(cctx_T *cctx, job_T *job)
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1047 {
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1048 isn_T *isn;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1049
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1050 RETURN_OK_IF_SKIP(cctx);
19572
6b6e97d0185e patch 8.2.0343: Vim9: using wrong instruction, limited test coverage
Bram Moolenaar <Bram@vim.org>
parents: 19566
diff changeset
1051 if ((isn = generate_instr_type(cctx, ISN_PUSHJOB, &t_channel)) == NULL)
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1052 return FAIL;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1053 isn->isn_arg.job = job;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1054
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1055 return OK;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1056 }
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1057
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1058 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 * Generate an ISN_PUSHBLOB instruction.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 * Consumes "blob".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 generate_PUSHBLOB(cctx_T *cctx, blob_T *blob)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1067 RETURN_OK_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 if ((isn = generate_instr_type(cctx, ISN_PUSHBLOB, &t_blob)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 isn->isn_arg.blob = blob;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 /*
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1076 * Generate an ISN_PUSHFUNC instruction with name "name".
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1077 * Consumes "name".
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1078 */
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1079 static int
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
1080 generate_PUSHFUNC(cctx_T *cctx, char_u *name, type_T *type)
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1081 {
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1082 isn_T *isn;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1083
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1084 RETURN_OK_IF_SKIP(cctx);
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
1085 if ((isn = generate_instr_type(cctx, ISN_PUSHFUNC, type)) == NULL)
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1086 return FAIL;
21473
8bcd1ee2630b patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
1087 isn->isn_arg.string = name == NULL ? NULL : vim_strsave(name);
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1088
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1089 return OK;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1090 }
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1091
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1092 /*
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1093 * Generate an ISN_GETITEM instruction with "index".
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1094 */
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1095 static int
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1096 generate_GETITEM(cctx_T *cctx, int index)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1097 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1098 isn_T *isn;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1099 garray_T *stack = &cctx->ctx_type_stack;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1100 type_T *type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1101 type_T *item_type = &t_any;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1102
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1103 RETURN_OK_IF_SKIP(cctx);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1104
21421
0f0fee4122d3 patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents: 21411
diff changeset
1105 if (type->tt_type != VAR_LIST)
0f0fee4122d3 patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents: 21411
diff changeset
1106 {
0f0fee4122d3 patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents: 21411
diff changeset
1107 // cannot happen, caller has checked the type
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1108 emsg(_(e_listreq));
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1109 return FAIL;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1110 }
21421
0f0fee4122d3 patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents: 21411
diff changeset
1111 item_type = type->tt_member;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1112 if ((isn = generate_instr(cctx, ISN_GETITEM)) == NULL)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1113 return FAIL;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1114 isn->isn_arg.number = index;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1115
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1116 // add the item type to the type stack
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1117 if (ga_grow(stack, 1) == FAIL)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1118 return FAIL;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1119 ((type_T **)stack->ga_data)[stack->ga_len] = item_type;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1120 ++stack->ga_len;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1121 return OK;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1122 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1123
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1124 /*
20871
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1125 * Generate an ISN_SLICE instruction with "count".
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1126 */
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1127 static int
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1128 generate_SLICE(cctx_T *cctx, int count)
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1129 {
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1130 isn_T *isn;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1131
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1132 RETURN_OK_IF_SKIP(cctx);
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1133 if ((isn = generate_instr(cctx, ISN_SLICE)) == NULL)
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1134 return FAIL;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1135 isn->isn_arg.number = count;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1136 return OK;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1137 }
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1138
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1139 /*
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1140 * Generate an ISN_CHECKLEN instruction with "min_len".
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1141 */
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1142 static int
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1143 generate_CHECKLEN(cctx_T *cctx, int min_len, int more_OK)
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1144 {
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1145 isn_T *isn;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1146
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1147 RETURN_OK_IF_SKIP(cctx);
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1148
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1149 if ((isn = generate_instr(cctx, ISN_CHECKLEN)) == NULL)
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1150 return FAIL;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1151 isn->isn_arg.checklen.cl_min_len = min_len;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1152 isn->isn_arg.checklen.cl_more_OK = more_OK;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1153
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1154 return OK;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1155 }
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1156
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1157 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 * Generate an ISN_STORE instruction.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 generate_STORE(cctx_T *cctx, isntype_T isn_type, int idx, char_u *name)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1165 RETURN_OK_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166 if ((isn = generate_instr_drop(cctx, isn_type, 1)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168 if (name != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 isn->isn_arg.string = vim_strsave(name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 isn->isn_arg.number = idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 * Generate an ISN_STORENR instruction (short for ISN_PUSHNR + ISN_STORE)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180 generate_STORENR(cctx_T *cctx, int idx, varnumber_T value)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1184 RETURN_OK_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 if ((isn = generate_instr(cctx, ISN_STORENR)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 return FAIL;
19597
1098989a90ee patch 8.2.0355: Vim9: str_val is confusing, it's a number
Bram Moolenaar <Bram@vim.org>
parents: 19587
diff changeset
1187 isn->isn_arg.storenr.stnr_idx = idx;
1098989a90ee patch 8.2.0355: Vim9: str_val is confusing, it's a number
Bram Moolenaar <Bram@vim.org>
parents: 19587
diff changeset
1188 isn->isn_arg.storenr.stnr_val = value;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 * Generate an ISN_STOREOPT instruction
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 generate_STOREOPT(cctx_T *cctx, char_u *name, int opt_flags)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1201 RETURN_OK_IF_SKIP(cctx);
21681
877321650f7f patch 8.2.1390: Vim9: type error after storing an option value
Bram Moolenaar <Bram@vim.org>
parents: 21677
diff changeset
1202 if ((isn = generate_instr_drop(cctx, ISN_STOREOPT, 1)) == NULL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 isn->isn_arg.storeopt.so_name = vim_strsave(name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205 isn->isn_arg.storeopt.so_flags = opt_flags;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1209
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211 * Generate an ISN_LOAD or similar instruction.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1214 generate_LOAD(
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 cctx_T *cctx,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 isntype_T isn_type,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 int idx,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 char_u *name,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 type_T *type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1223 RETURN_OK_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 if ((isn = generate_instr_type(cctx, isn_type, type)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 if (name != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 isn->isn_arg.string = vim_strsave(name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 isn->isn_arg.number = idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1232 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234 /*
19960
3c11b9f6fa03 patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1235 * Generate an ISN_LOADV instruction for v:var.
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1236 */
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1237 static int
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1238 generate_LOADV(
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1239 cctx_T *cctx,
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1240 char_u *name,
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1241 int error)
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1242 {
19960
3c11b9f6fa03 patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1243 int di_flags;
3c11b9f6fa03 patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1244 int vidx = find_vim_var(name, &di_flags);
3c11b9f6fa03 patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1245 type_T *type;
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1246
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1247 RETURN_OK_IF_SKIP(cctx);
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1248 if (vidx < 0)
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1249 {
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1250 if (error)
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
1251 semsg(_(e_variable_not_found_str), name);
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1252 return FAIL;
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1253 }
21443
66386ca8a69f patch 8.2.1272: Vim9: type not checked if declaration also assigns value
Bram Moolenaar <Bram@vim.org>
parents: 21441
diff changeset
1254 type = typval2type_vimvar(get_vim_var_tv(vidx), cctx->ctx_type_list);
19960
3c11b9f6fa03 patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1255
3c11b9f6fa03 patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1256 return generate_LOAD(cctx, ISN_LOADV, vidx, NULL, type);
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1257 }
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1258
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1259 /*
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1260 * Generate an ISN_UNLET instruction.
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1261 */
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1262 static int
20099
058b41f85bcb patch 8.2.0605: Vim9: cannot unlet an environment variable
Bram Moolenaar <Bram@vim.org>
parents: 20091
diff changeset
1263 generate_UNLET(cctx_T *cctx, isntype_T isn_type, char_u *name, int forceit)
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1264 {
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1265 isn_T *isn;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1266
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1267 RETURN_OK_IF_SKIP(cctx);
20099
058b41f85bcb patch 8.2.0605: Vim9: cannot unlet an environment variable
Bram Moolenaar <Bram@vim.org>
parents: 20091
diff changeset
1268 if ((isn = generate_instr(cctx, isn_type)) == NULL)
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1269 return FAIL;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1270 isn->isn_arg.unlet.ul_name = vim_strsave(name);
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1271 isn->isn_arg.unlet.ul_forceit = forceit;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1272
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1273 return OK;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1274 }
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1275
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1276 /*
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1277 * Generate an ISN_LOCKCONST instruction.
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1278 */
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1279 static int
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1280 generate_LOCKCONST(cctx_T *cctx)
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1281 {
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1282 isn_T *isn;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1283
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1284 RETURN_OK_IF_SKIP(cctx);
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1285 if ((isn = generate_instr(cctx, ISN_LOCKCONST)) == NULL)
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1286 return FAIL;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1287 return OK;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1288 }
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1289
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1290 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 * Generate an ISN_LOADS instruction.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 static int
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1294 generate_OLDSCRIPT(
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 cctx_T *cctx,
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1296 isntype_T isn_type,
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297 char_u *name,
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1298 int sid,
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1299 type_T *type)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1303 RETURN_OK_IF_SKIP(cctx);
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1304 if (isn_type == ISN_LOADS)
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1305 isn = generate_instr_type(cctx, isn_type, type);
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1306 else
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1307 isn = generate_instr_drop(cctx, isn_type, 1);
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1308 if (isn == NULL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309 return FAIL;
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1310 isn->isn_arg.loadstore.ls_name = vim_strsave(name);
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1311 isn->isn_arg.loadstore.ls_sid = sid;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1312
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1313 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1315
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1317 * Generate an ISN_LOADSCRIPT or ISN_STORESCRIPT instruction.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1318 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1319 static int
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1320 generate_VIM9SCRIPT(
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1321 cctx_T *cctx,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1322 isntype_T isn_type,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1323 int sid,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1324 int idx,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325 type_T *type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 isn_T *isn;
23330
e8eb4fd44902 patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents: 23318
diff changeset
1328 scriptref_T *sref;
e8eb4fd44902 patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents: 23318
diff changeset
1329 scriptitem_T *si = SCRIPT_ITEM(sid);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1331 RETURN_OK_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 if (isn_type == ISN_LOADSCRIPT)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 isn = generate_instr_type(cctx, isn_type, type);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 isn = generate_instr_drop(cctx, isn_type, 1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 if (isn == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1337 return FAIL;
23330
e8eb4fd44902 patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents: 23318
diff changeset
1338
e8eb4fd44902 patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents: 23318
diff changeset
1339 // This requires three arguments, which doesn't fit in an instruction, thus
e8eb4fd44902 patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents: 23318
diff changeset
1340 // we need to allocate a struct for this.
e8eb4fd44902 patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents: 23318
diff changeset
1341 sref = ALLOC_ONE(scriptref_T);
e8eb4fd44902 patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents: 23318
diff changeset
1342 if (sref == NULL)
e8eb4fd44902 patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents: 23318
diff changeset
1343 return FAIL;
e8eb4fd44902 patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents: 23318
diff changeset
1344 isn->isn_arg.script.scriptref = sref;
e8eb4fd44902 patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents: 23318
diff changeset
1345 sref->sref_sid = sid;
e8eb4fd44902 patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents: 23318
diff changeset
1346 sref->sref_idx = idx;
e8eb4fd44902 patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents: 23318
diff changeset
1347 sref->sref_seq = si->sn_script_seq;
23362
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23360
diff changeset
1348 sref->sref_type = type;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1349 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1350 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1351
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1353 * Generate an ISN_NEWLIST instruction.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1356 generate_NEWLIST(cctx_T *cctx, int count)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1359 garray_T *stack = &cctx->ctx_type_stack;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1360 type_T *type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 type_T *member;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1362
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1363 RETURN_OK_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1364 if ((isn = generate_instr(cctx, ISN_NEWLIST)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 isn->isn_arg.number = count;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367
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
1368 // get the member type from all the items on the stack.
22021
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1369 if (count == 0)
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1370 member = &t_void;
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1371 else
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1372 member = get_member_type_from_stack(
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
1373 ((type_T **)stack->ga_data) + stack->ga_len, count, 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
1374 cctx->ctx_type_list);
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
1375 type = get_list_type(member, cctx->ctx_type_list);
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
1376
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1377 // drop the value types
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378 stack->ga_len -= count;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1380 // add the list type to the type stack
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381 if (ga_grow(stack, 1) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1382 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383 ((type_T **)stack->ga_data)[stack->ga_len] = type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384 ++stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1386 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1387 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390 * Generate an ISN_NEWDICT instruction.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1391 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1392 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393 generate_NEWDICT(cctx_T *cctx, int count)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1394 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1396 garray_T *stack = &cctx->ctx_type_stack;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1397 type_T *type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1398 type_T *member;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1399
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1400 RETURN_OK_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1401 if ((isn = generate_instr(cctx, ISN_NEWDICT)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 isn->isn_arg.number = count;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404
22021
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1405 if (count == 0)
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1406 member = &t_void;
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1407 else
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1408 member = get_member_type_from_stack(
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
1409 ((type_T **)stack->ga_data) + stack->ga_len, count, 2,
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
1410 cctx->ctx_type_list);
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
1411 type = get_dict_type(member, cctx->ctx_type_list);
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
1412
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413 // drop the key and value types
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1414 stack->ga_len -= 2 * count;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1415
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1416 // add the dict type to the type stack
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 if (ga_grow(stack, 1) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1419 ((type_T **)stack->ga_data)[stack->ga_len] = type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420 ++stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1421
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1422 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1423 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1424
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1426 * Generate an ISN_FUNCREF instruction.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1427 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1428 static int
21693
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
1429 generate_FUNCREF(cctx_T *cctx, ufunc_T *ufunc)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1430 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1431 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1432 garray_T *stack = &cctx->ctx_type_stack;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1433
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1434 RETURN_OK_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1435 if ((isn = generate_instr(cctx, ISN_FUNCREF)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1436 return FAIL;
21693
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
1437 isn->isn_arg.funcref.fr_func = ufunc->uf_dfunc_idx;
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22369
diff changeset
1438 cctx->ctx_has_closure = 1;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1439
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440 if (ga_grow(stack, 1) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1441 return FAIL;
21693
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
1442 ((type_T **)stack->ga_data)[stack->ga_len] =
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
1443 ufunc->uf_func_type == NULL ? &t_func_any : ufunc->uf_func_type;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1444 ++stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1445
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1446 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1447 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1448
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1449 /*
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1450 * Generate an ISN_NEWFUNC instruction.
23291
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1451 * "lambda_name" and "func_name" must be in allocated memory and will be
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1452 * consumed.
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1453 */
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1454 static int
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1455 generate_NEWFUNC(cctx_T *cctx, char_u *lambda_name, char_u *func_name)
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1456 {
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1457 isn_T *isn;
23291
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1458
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1459 if (cctx->ctx_skip == SKIP_YES)
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1460 {
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1461 vim_free(lambda_name);
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1462 vim_free(func_name);
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1463 return OK;
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1464 }
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1465 if ((isn = generate_instr(cctx, ISN_NEWFUNC)) == NULL)
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1466 {
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1467 vim_free(lambda_name);
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1468 vim_free(func_name);
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1469 return FAIL;
23291
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1470 }
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1471 isn->isn_arg.newfunc.nf_lambda = lambda_name;
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1472 isn->isn_arg.newfunc.nf_global = func_name;
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1473
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1474 return OK;
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1475 }
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1476
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1477 /*
22973
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1478 * Generate an ISN_DEF instruction: list functions
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1479 */
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1480 static int
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1481 generate_DEF(cctx_T *cctx, char_u *name, size_t len)
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1482 {
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1483 isn_T *isn;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1484
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1485 RETURN_OK_IF_SKIP(cctx);
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1486 if ((isn = generate_instr(cctx, ISN_DEF)) == NULL)
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1487 return FAIL;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1488 if (len > 0)
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1489 {
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1490 isn->isn_arg.string = vim_strnsave(name, len);
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1491 if (isn->isn_arg.string == NULL)
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1492 return FAIL;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1493 }
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1494 return OK;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1495 }
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1496
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1497 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1498 * Generate an ISN_JUMP instruction.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1499 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1500 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1501 generate_JUMP(cctx_T *cctx, jumpwhen_T when, int where)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1502 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1503 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1504 garray_T *stack = &cctx->ctx_type_stack;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1505
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1506 RETURN_OK_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1507 if ((isn = generate_instr(cctx, ISN_JUMP)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509 isn->isn_arg.jump.jump_when = when;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 isn->isn_arg.jump.jump_where = where;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1511
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1512 if (when != JUMP_ALWAYS && stack->ga_len > 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513 --stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1514
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1515 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1516 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1517
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1518 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1519 generate_FOR(cctx_T *cctx, int loop_idx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1520 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 garray_T *stack = &cctx->ctx_type_stack;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1523
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1524 RETURN_OK_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1525 if ((isn = generate_instr(cctx, ISN_FOR)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1527 isn->isn_arg.forloop.for_idx = loop_idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1528
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1529 if (ga_grow(stack, 1) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1530 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1531 // type doesn't matter, will be stored next
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1532 ((type_T **)stack->ga_data)[stack->ga_len] = &t_any;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1533 ++stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1534
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1535 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1536 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1539 * Generate an ISN_BCALL instruction.
21232
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
1540 * "method_call" is TRUE for "value->method()"
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1541 * Return FAIL if the number of arguments is wrong.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1542 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1543 static int
21232
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
1544 generate_BCALL(cctx_T *cctx, int func_idx, int argcount, int method_call)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1545 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1546 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547 garray_T *stack = &cctx->ctx_type_stack;
21232
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
1548 int argoff;
22671
ad54acb1bf2c patch 8.2.1884: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents: 22667
diff changeset
1549 type_T **argtypes = NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1551 RETURN_OK_IF_SKIP(cctx);
21232
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
1552 argoff = check_internal_func(func_idx, argcount);
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
1553 if (argoff < 0)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555
21232
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
1556 if (method_call && argoff > 1)
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
1557 {
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
1558 if ((isn = generate_instr(cctx, ISN_SHUFFLE)) == NULL)
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
1559 return FAIL;
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
1560 isn->isn_arg.shuffle.shfl_item = argcount;
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
1561 isn->isn_arg.shuffle.shfl_up = argoff - 1;
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
1562 }
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
1563
22663
0f90c15a4a28 patch 8.2.1880: Vim9: asan complains about adding zero to NULL
Bram Moolenaar <Bram@vim.org>
parents: 22661
diff changeset
1564 if (argcount > 0)
0f90c15a4a28 patch 8.2.1880: Vim9: asan complains about adding zero to NULL
Bram Moolenaar <Bram@vim.org>
parents: 22661
diff changeset
1565 {
0f90c15a4a28 patch 8.2.1880: Vim9: asan complains about adding zero to NULL
Bram Moolenaar <Bram@vim.org>
parents: 22661
diff changeset
1566 // Check the types of the arguments.
0f90c15a4a28 patch 8.2.1880: Vim9: asan complains about adding zero to NULL
Bram Moolenaar <Bram@vim.org>
parents: 22661
diff changeset
1567 argtypes = ((type_T **)stack->ga_data) + stack->ga_len - argcount;
0f90c15a4a28 patch 8.2.1880: Vim9: asan complains about adding zero to NULL
Bram Moolenaar <Bram@vim.org>
parents: 22661
diff changeset
1568 if (internal_func_check_arg_types(argtypes, func_idx, argcount) == FAIL)
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22639
diff changeset
1569 return FAIL;
22663
0f90c15a4a28 patch 8.2.1880: Vim9: asan complains about adding zero to NULL
Bram Moolenaar <Bram@vim.org>
parents: 22661
diff changeset
1570 }
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22639
diff changeset
1571
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1572 if ((isn = generate_instr(cctx, ISN_BCALL)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1573 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574 isn->isn_arg.bfunc.cbf_idx = func_idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1575 isn->isn_arg.bfunc.cbf_argcount = argcount;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22639
diff changeset
1577 // Drop the argument types and push the return type.
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22639
diff changeset
1578 stack->ga_len -= argcount;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1579 if (ga_grow(stack, 1) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1580 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581 ((type_T **)stack->ga_data)[stack->ga_len] =
19564
06f29b6ea04a patch 8.2.0339: Vim9: function return type may depend on arguments
Bram Moolenaar <Bram@vim.org>
parents: 19562
diff changeset
1582 internal_func_ret_type(func_idx, argcount, argtypes);
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22639
diff changeset
1583 ++stack->ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1584
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1585 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1586 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1587
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1588 /*
22633
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1589 * Generate an ISN_LISTAPPEND instruction. Works like add().
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1590 * Argument count is already checked.
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1591 */
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1592 static int
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1593 generate_LISTAPPEND(cctx_T *cctx)
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1594 {
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1595 garray_T *stack = &cctx->ctx_type_stack;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1596 type_T *list_type;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1597 type_T *item_type;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1598 type_T *expected;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1599
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1600 // Caller already checked that list_type is a list.
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1601 list_type = ((type_T **)stack->ga_data)[stack->ga_len - 2];
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1602 item_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1603 expected = list_type->tt_member;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1604 if (need_type(item_type, expected, -1, cctx, FALSE, FALSE) == FAIL)
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1605 return FAIL;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1606
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1607 if (generate_instr(cctx, ISN_LISTAPPEND) == NULL)
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1608 return FAIL;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1609
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1610 --stack->ga_len; // drop the argument
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1611 return OK;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1612 }
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1613
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1614 /*
22637
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1615 * Generate an ISN_BLOBAPPEND instruction. Works like add().
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1616 * Argument count is already checked.
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1617 */
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1618 static int
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1619 generate_BLOBAPPEND(cctx_T *cctx)
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1620 {
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1621 garray_T *stack = &cctx->ctx_type_stack;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1622 type_T *item_type;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1623
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1624 // Caller already checked that blob_type is a blob.
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1625 item_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1626 if (need_type(item_type, &t_number, -1, cctx, FALSE, FALSE) == FAIL)
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1627 return FAIL;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1628
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1629 if (generate_instr(cctx, ISN_BLOBAPPEND) == NULL)
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1630 return FAIL;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1631
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1632 --stack->ga_len; // drop the argument
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1633 return OK;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1634 }
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1635
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1636 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1637 * Generate an ISN_DCALL or ISN_UCALL instruction.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1638 * Return FAIL if the number of arguments is wrong.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1639 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1640 static int
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
1641 generate_CALL(cctx_T *cctx, ufunc_T *ufunc, int pushed_argcount)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1642 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1643 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1644 garray_T *stack = &cctx->ctx_type_stack;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1645 int regular_args = ufunc->uf_args.ga_len;
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
1646 int argcount = pushed_argcount;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1647
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1648 RETURN_OK_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1649 if (argcount > regular_args && !has_varargs(ufunc))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650 {
22318
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22292
diff changeset
1651 semsg(_(e_toomanyarg), printable_func_name(ufunc));
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1652 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1653 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1654 if (argcount < regular_args - ufunc->uf_def_args.ga_len)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1655 {
22318
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22292
diff changeset
1656 semsg(_(e_toofewarg), printable_func_name(ufunc));
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1657 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1659
20943
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
1660 if (ufunc->uf_def_status != UF_NOT_COMPILED)
19944
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1661 {
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1662 int i;
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1663
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1664 for (i = 0; i < argcount; ++i)
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1665 {
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1666 type_T *expected;
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1667 type_T *actual;
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1668
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1669 if (i < regular_args)
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1670 {
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1671 if (ufunc->uf_arg_types == NULL)
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1672 continue;
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1673 expected = ufunc->uf_arg_types[i];
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1674 }
22292
3515f341e8ac patch 8.2.1695: Vim9: crash when using varargs type "any"
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
1675 else if (ufunc->uf_va_type == NULL || ufunc->uf_va_type == &t_any)
3515f341e8ac patch 8.2.1695: Vim9: crash when using varargs type "any"
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
1676 // possibly a lambda or "...: any"
21809
15ed135796fd patch 8.2.1454: Vim9: failure invoking lambda with wrong arguments
Bram Moolenaar <Bram@vim.org>
parents: 21805
diff changeset
1677 expected = &t_any;
19944
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1678 else
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1679 expected = ufunc->uf_va_type->tt_member;
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1680 actual = ((type_T **)stack->ga_data)[stack->ga_len - argcount + i];
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
1681 if (need_type(actual, expected, -argcount + i, cctx,
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
1682 TRUE, FALSE) == FAIL)
19944
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1683 {
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1684 arg_type_mismatch(expected, actual, i + 1);
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1685 return FAIL;
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1686 }
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1687 }
20943
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
1688 if (ufunc->uf_def_status == UF_TO_BE_COMPILED)
21693
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
1689 if (compile_def_function(ufunc, ufunc->uf_ret_type == NULL, NULL)
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
1690 == FAIL)
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20419
diff changeset
1691 return FAIL;
19944
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1692 }
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1693
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1694 if ((isn = generate_instr(cctx,
20943
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
1695 ufunc->uf_def_status != UF_NOT_COMPILED ? ISN_DCALL
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20419
diff changeset
1696 : ISN_UCALL)) == NULL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1697 return FAIL;
22326
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
1698 if (isn->isn_type == ISN_DCALL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1699 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1700 isn->isn_arg.dfunc.cdf_idx = ufunc->uf_dfunc_idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1701 isn->isn_arg.dfunc.cdf_argcount = argcount;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1702 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1703 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1704 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1705 // A user function may be deleted and redefined later, can't use the
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1706 // ufunc pointer, need to look it up again at runtime.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1707 isn->isn_arg.ufunc.cuf_name = vim_strsave(ufunc->uf_name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1708 isn->isn_arg.ufunc.cuf_argcount = argcount;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1709 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1710
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1711 stack->ga_len -= argcount; // drop the arguments
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1712 if (ga_grow(stack, 1) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1713 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1714 // add return value
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1715 ((type_T **)stack->ga_data)[stack->ga_len] = ufunc->uf_ret_type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1716 ++stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1717
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1718 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1719 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1720
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1721 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1722 * Generate an ISN_UCALL instruction when the function isn't defined yet.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1723 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1724 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1725 generate_UCALL(cctx_T *cctx, char_u *name, int argcount)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1726 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1727 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1728 garray_T *stack = &cctx->ctx_type_stack;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1729
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1730 RETURN_OK_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1731 if ((isn = generate_instr(cctx, ISN_UCALL)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1732 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1733 isn->isn_arg.ufunc.cuf_name = vim_strsave(name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1734 isn->isn_arg.ufunc.cuf_argcount = argcount;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1735
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1736 stack->ga_len -= argcount; // drop the arguments
19295
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
1737 if (ga_grow(stack, 1) == FAIL)
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
1738 return FAIL;
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
1739 // add return value
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
1740 ((type_T **)stack->ga_data)[stack->ga_len] = &t_any;
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
1741 ++stack->ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1742
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1743 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1744 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1745
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1746 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1747 * Generate an ISN_PCALL instruction.
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1748 * "type" is the type of the FuncRef.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1749 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1750 static int
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1751 generate_PCALL(
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1752 cctx_T *cctx,
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1753 int argcount,
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1754 char_u *name,
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1755 type_T *type,
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1756 int at_top)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1757 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1758 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1759 garray_T *stack = &cctx->ctx_type_stack;
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1760 type_T *ret_type;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1761
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1762 RETURN_OK_IF_SKIP(cctx);
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
1763
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1764 if (type->tt_type == VAR_ANY)
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1765 ret_type = &t_any;
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1766 else if (type->tt_type == VAR_FUNC || type->tt_type == VAR_PARTIAL)
20281
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
1767 {
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
1768 if (type->tt_argcount != -1)
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
1769 {
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
1770 int varargs = (type->tt_flags & TTFLAG_VARARGS) ? 1 : 0;
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
1771
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
1772 if (argcount < type->tt_min_argcount - varargs)
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
1773 {
22734
02b782e80ee4 patch 8.2.1915: Vim9: error for wrong number of arguments is not useful
Bram Moolenaar <Bram@vim.org>
parents: 22703
diff changeset
1774 semsg(_(e_toofewarg), name);
20281
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
1775 return FAIL;
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
1776 }
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
1777 if (!varargs && argcount > type->tt_argcount)
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
1778 {
22734
02b782e80ee4 patch 8.2.1915: Vim9: error for wrong number of arguments is not useful
Bram Moolenaar <Bram@vim.org>
parents: 22703
diff changeset
1779 semsg(_(e_toomanyarg), name);
20281
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
1780 return FAIL;
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
1781 }
22816
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1782 if (type->tt_args != NULL)
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1783 {
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1784 int i;
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1785
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1786 for (i = 0; i < argcount; ++i)
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1787 {
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1788 int offset = -argcount + i - 1;
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1789 type_T *actual = ((type_T **)stack->ga_data)[
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1790 stack->ga_len + offset];
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1791 type_T *expected;
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1792
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1793 if (varargs && i >= type->tt_min_argcount - 1)
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1794 expected = type->tt_args[
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1795 type->tt_min_argcount - 1]->tt_member;
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1796 else
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1797 expected = type->tt_args[i];
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1798 if (need_type(actual, expected, offset,
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1799 cctx, TRUE, FALSE) == FAIL)
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1800 {
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1801 arg_type_mismatch(expected, actual, i + 1);
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1802 return FAIL;
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1803 }
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1804 }
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
1805 }
20281
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
1806 }
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1807 ret_type = type->tt_member;
20281
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
1808 }
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1809 else
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1810 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
1811 semsg(_(e_not_callable_type_str), name);
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1812 return FAIL;
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1813 }
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1814
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1815 if ((isn = generate_instr(cctx, ISN_PCALL)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1816 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1817 isn->isn_arg.pfunc.cpf_top = at_top;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1818 isn->isn_arg.pfunc.cpf_argcount = argcount;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1819
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1820 stack->ga_len -= argcount; // drop the arguments
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1821
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1822 // drop the funcref/partial, get back the return value
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1823 ((type_T **)stack->ga_data)[stack->ga_len - 1] = ret_type;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1824
19862
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19860
diff changeset
1825 // If partial is above the arguments it must be cleared and replaced with
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19860
diff changeset
1826 // the return value.
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19860
diff changeset
1827 if (at_top && generate_instr(cctx, ISN_PCALL_END) == NULL)
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19860
diff changeset
1828 return FAIL;
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19860
diff changeset
1829
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1830 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1831 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1832
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1833 /*
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
1834 * Generate an ISN_STRINGMEMBER instruction.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1835 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1836 static int
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
1837 generate_STRINGMEMBER(cctx_T *cctx, char_u *name, size_t len)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1838 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1839 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1840 garray_T *stack = &cctx->ctx_type_stack;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1841 type_T *type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1842
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1843 RETURN_OK_IF_SKIP(cctx);
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
1844 if ((isn = generate_instr(cctx, ISN_STRINGMEMBER)) == NULL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1845 return FAIL;
20830
9064044fd4f6 patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
1846 isn->isn_arg.string = vim_strnsave(name, len);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1847
19461
08ef11a81daa patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
1848 // check for dict type
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1849 type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
19461
08ef11a81daa patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
1850 if (type->tt_type != VAR_DICT && type != &t_any)
08ef11a81daa patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
1851 {
08ef11a81daa patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
1852 emsg(_(e_dictreq));
08ef11a81daa patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
1853 return FAIL;
08ef11a81daa patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
1854 }
08ef11a81daa patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
1855 // change dict type to dict member type
08ef11a81daa patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
1856 if (type->tt_type == VAR_DICT)
08ef11a81daa patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
1857 ((type_T **)stack->ga_data)[stack->ga_len - 1] = type->tt_member;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1858
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1859 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1860 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1861
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1862 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1863 * Generate an ISN_ECHO instruction.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1864 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1865 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1866 generate_ECHO(cctx_T *cctx, int with_white, int count)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1867 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1868 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1869
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1870 RETURN_OK_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1871 if ((isn = generate_instr_drop(cctx, ISN_ECHO, count)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1872 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1873 isn->isn_arg.echo.echo_with_white = with_white;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1874 isn->isn_arg.echo.echo_count = count;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1875
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1876 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1877 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1878
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
1879 /*
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1880 * Generate an ISN_EXECUTE/ISN_ECHOMSG/ISN_ECHOERR instruction.
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
1881 */
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
1882 static int
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1883 generate_MULT_EXPR(cctx_T *cctx, isntype_T isn_type, int count)
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
1884 {
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
1885 isn_T *isn;
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
1886
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1887 if ((isn = generate_instr_drop(cctx, isn_type, count)) == NULL)
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
1888 return FAIL;
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
1889 isn->isn_arg.number = count;
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
1890
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
1891 return OK;
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
1892 }
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
1893
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
1894 /*
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
1895 * Generate an ISN_PUT instruction.
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
1896 */
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
1897 static int
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
1898 generate_PUT(cctx_T *cctx, int regname, linenr_T lnum)
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
1899 {
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
1900 isn_T *isn;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
1901
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
1902 RETURN_OK_IF_SKIP(cctx);
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
1903 if ((isn = generate_instr(cctx, ISN_PUT)) == NULL)
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
1904 return FAIL;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
1905 isn->isn_arg.put.put_regname = regname;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
1906 isn->isn_arg.put.put_lnum = lnum;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
1907 return OK;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
1908 }
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
1909
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1910 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1911 generate_EXEC(cctx_T *cctx, char_u *line)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1912 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1913 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1914
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1915 RETURN_OK_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1916 if ((isn = generate_instr(cctx, ISN_EXEC)) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1917 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1918 isn->isn_arg.string = vim_strsave(line);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1919 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1920 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1921
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1922 static int
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1923 generate_EXECCONCAT(cctx_T *cctx, int count)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1924 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1925 isn_T *isn;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1926
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1927 if ((isn = generate_instr_drop(cctx, ISN_EXECCONCAT, count)) == NULL)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1928 return FAIL;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1929 isn->isn_arg.number = count;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1930 return OK;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1931 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1932
23156
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1933 /*
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1934 * Generate ISN_RANGE. Consumes "range". Return OK/FAIL.
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1935 */
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1936 static int
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1937 generate_RANGE(cctx_T *cctx, char_u *range)
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1938 {
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1939 isn_T *isn;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1940 garray_T *stack = &cctx->ctx_type_stack;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1941
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1942 if ((isn = generate_instr(cctx, ISN_RANGE)) == NULL)
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1943 return FAIL;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1944 isn->isn_arg.string = range;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1945
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1946 if (ga_grow(stack, 1) == FAIL)
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1947 return FAIL;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1948 ((type_T **)stack->ga_data)[stack->ga_len] = &t_number;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1949 ++stack->ga_len;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1950 return OK;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1951 }
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
1952
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
1953 static int
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
1954 generate_UNPACK(cctx_T *cctx, int var_count, int semicolon)
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
1955 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
1956 isn_T *isn;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
1957
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
1958 RETURN_OK_IF_SKIP(cctx);
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
1959 if ((isn = generate_instr(cctx, ISN_UNPACK)) == NULL)
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
1960 return FAIL;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
1961 isn->isn_arg.unpack.unp_count = var_count;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
1962 isn->isn_arg.unpack.unp_semicolon = semicolon;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
1963 return OK;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
1964 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
1965
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1966 /*
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
1967 * Generate an instruction for any command modifiers.
22691
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
1968 */
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
1969 static int
22699
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 22697
diff changeset
1970 generate_cmdmods(cctx_T *cctx, cmdmod_T *cmod)
22691
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
1971 {
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
1972 isn_T *isn;
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
1973
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
1974 if (cmod->cmod_flags != 0
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
1975 || cmod->cmod_split != 0
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
1976 || cmod->cmod_verbose != 0
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
1977 || cmod->cmod_tab != 0
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
1978 || cmod->cmod_filter_regmatch.regprog != NULL)
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
1979 {
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
1980 cctx->ctx_has_cmdmod = TRUE;
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
1981
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
1982 if ((isn = generate_instr(cctx, ISN_CMDMOD)) == NULL)
22691
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
1983 return FAIL;
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
1984 isn->isn_arg.cmdmod.cf_cmdmod = ALLOC_ONE(cmdmod_T);
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
1985 if (isn->isn_arg.cmdmod.cf_cmdmod == NULL)
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
1986 return FAIL;
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
1987 mch_memmove(isn->isn_arg.cmdmod.cf_cmdmod, cmod, sizeof(cmdmod_T));
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 23199
diff changeset
1988 // filter program now belongs to the instruction
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
1989 cmod->cmod_filter_regmatch.regprog = NULL;
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
1990 }
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
1991
22691
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
1992 return OK;
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
1993 }
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
1994
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
1995 static int
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
1996 generate_undo_cmdmods(cctx_T *cctx)
22691
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
1997 {
23100
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23088
diff changeset
1998 if (cctx->ctx_has_cmdmod && generate_instr(cctx, ISN_CMDMOD_REV) == NULL)
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23088
diff changeset
1999 return FAIL;
22691
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2000 return OK;
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2001 }
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2002
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2003 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2004 * Reserve space for a local variable.
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2005 * Return the variable or NULL if it failed.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2006 */
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2007 static lvar_T *
22537
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22508
diff changeset
2008 reserve_local(
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22508
diff changeset
2009 cctx_T *cctx,
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22508
diff changeset
2010 char_u *name,
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22508
diff changeset
2011 size_t len,
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22508
diff changeset
2012 int isConst,
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22508
diff changeset
2013 type_T *type)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2014 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2015 lvar_T *lvar;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2016
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2017 if (arg_exists(name, len, NULL, NULL, NULL, cctx) == OK)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2018 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2019 emsg_namelen(_(e_str_is_used_as_argument), name, (int)len);
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2020 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2021 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2022
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2023 if (ga_grow(&cctx->ctx_locals, 1) == FAIL)
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2024 return NULL;
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2025 lvar = ((lvar_T *)cctx->ctx_locals.ga_data) + cctx->ctx_locals.ga_len++;
22537
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22508
diff changeset
2026 CLEAR_POINTER(lvar);
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2027
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2028 // Every local variable uses the next entry on the stack. We could re-use
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2029 // the last ones when leaving a scope, but then variables used in a closure
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2030 // might get overwritten. To keep things simple do not re-use stack
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2031 // entries. This is less efficient, but memory is cheap these days.
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2032 lvar->lv_idx = cctx->ctx_locals_count++;
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2033
20830
9064044fd4f6 patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
2034 lvar->lv_name = vim_strnsave(name, len == 0 ? STRLEN(name) : len);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2035 lvar->lv_const = isConst;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2036 lvar->lv_type = type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2037
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2038 return lvar;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2039 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2040
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2041 /*
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2042 * Remove local variables above "new_top".
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2043 */
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2044 static void
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2045 unwind_locals(cctx_T *cctx, int new_top)
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2046 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2047 if (cctx->ctx_locals.ga_len > new_top)
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2048 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2049 int idx;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2050 lvar_T *lvar;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2051
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2052 for (idx = new_top; idx < cctx->ctx_locals.ga_len; ++idx)
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2053 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2054 lvar = ((lvar_T *)cctx->ctx_locals.ga_data) + idx;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2055 vim_free(lvar->lv_name);
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2056 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2057 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2058 cctx->ctx_locals.ga_len = new_top;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2059 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2060
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2061 /*
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2062 * Free all local variables.
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2063 */
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2064 static void
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2065 free_locals(cctx_T *cctx)
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2066 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2067 unwind_locals(cctx, 0);
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2068 ga_clear(&cctx->ctx_locals);
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2069 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2070
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2071 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2072 * Find "name" in script-local items of script "sid".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2073 * Returns the index in "sn_var_vals" if found.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2074 * If found but not in "sn_var_vals" returns -1.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2075 * If not found returns -2.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2076 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2077 int
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2078 get_script_item_idx(int sid, char_u *name, int check_writable, cctx_T *cctx)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2079 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2080 hashtab_T *ht;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2081 dictitem_T *di;
19191
133ef7ba4e4e patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
2082 scriptitem_T *si = SCRIPT_ITEM(sid);
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2083 svar_T *sv;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2084 int idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2085
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2086 if (!SCRIPT_ID_VALID(sid))
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2087 return -1;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2088 if (sid == current_sctx.sc_sid)
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2089 {
22598
c7ef64b85e9b patch 8.2.1847: Vim9: using negative value for unsigned type
Bram Moolenaar <Bram@vim.org>
parents: 22596
diff changeset
2090 sallvar_T *sav = find_script_var(name, 0, cctx);
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2091
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2092 if (sav == NULL)
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2093 return -2;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2094 idx = sav->sav_var_vals_idx;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2095 sv = ((svar_T *)si->sn_var_vals.ga_data) + idx;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2096 if (check_writable && sv->sv_const)
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2097 semsg(_(e_readonlyvar), name);
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2098 return idx;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2099 }
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2100
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2101 // First look the name up in the hashtable.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2102 ht = &SCRIPT_VARS(sid);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2103 di = find_var_in_ht(ht, 0, name, TRUE);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2104 if (di == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2105 return -2;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2106
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2107 // Now find the svar_T index in sn_var_vals.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2108 for (idx = 0; idx < si->sn_var_vals.ga_len; ++idx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2109 {
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2110 sv = ((svar_T *)si->sn_var_vals.ga_data) + idx;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2111 if (sv->sv_tv == &di->di_tv)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2112 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2113 if (check_writable && sv->sv_const)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2114 semsg(_(e_readonlyvar), name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2115 return idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2116 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2117 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2118 return -1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2119 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2120
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2121 /*
20840
0600ab7b9f09 patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2122 * Find "name" in imported items of the current script or in "cctx" if not
0600ab7b9f09 patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2123 * NULL.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2124 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2125 imported_T *
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
2126 find_imported(char_u *name, size_t len, cctx_T *cctx)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2127 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2128 int idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2129
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2130 if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
21110
8fb0e507491d patch 8.2.1106: crash when trying to use s: variable in typed command
Bram Moolenaar <Bram@vim.org>
parents: 21040
diff changeset
2131 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2132 if (cctx != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2133 for (idx = 0; idx < cctx->ctx_imports.ga_len; ++idx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2134 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2135 imported_T *import = ((imported_T *)cctx->ctx_imports.ga_data)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2136 + idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2137
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
2138 if (len == 0 ? STRCMP(name, import->imp_name) == 0
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
2139 : STRLEN(import->imp_name) == len
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
2140 && STRNCMP(name, import->imp_name, len) == 0)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2141 return import;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2142 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2143
21699
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2144 return find_imported_in_script(name, len, current_sctx.sc_sid);
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2145 }
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2146
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2147 imported_T *
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2148 find_imported_in_script(char_u *name, size_t len, int sid)
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2149 {
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2150 scriptitem_T *si;
21699
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2151 int idx;
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2152
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2153 if (!SCRIPT_ID_VALID(sid))
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2154 return NULL;
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2155 si = SCRIPT_ITEM(sid);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2156 for (idx = 0; idx < si->sn_imports.ga_len; ++idx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2157 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2158 imported_T *import = ((imported_T *)si->sn_imports.ga_data) + idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2159
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
2160 if (len == 0 ? STRCMP(name, import->imp_name) == 0
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
2161 : STRLEN(import->imp_name) == len
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
2162 && STRNCMP(name, import->imp_name, len) == 0)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2163 return import;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2164 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2165 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2166 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2167
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2168 /*
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2169 * Free all imported variables.
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2170 */
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2171 static void
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2172 free_imported(cctx_T *cctx)
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2173 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2174 int idx;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2175
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2176 for (idx = 0; idx < cctx->ctx_imports.ga_len; ++idx)
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2177 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2178 imported_T *import = ((imported_T *)cctx->ctx_imports.ga_data) + idx;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2179
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2180 vim_free(import->imp_name);
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2181 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2182 ga_clear(&cctx->ctx_imports);
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2183 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2184
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2185 /*
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2186 * Return a pointer to the next line that isn't empty or only contains a
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2187 * comment. Skips over white space.
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2188 * Returns NULL if there is none.
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2189 */
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
2190 char_u *
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
2191 peek_next_line_from_context(cctx_T *cctx)
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2192 {
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2193 int lnum = cctx->ctx_lnum;
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2194
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2195 while (++lnum < cctx->ctx_ufunc->uf_lines.ga_len)
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2196 {
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2197 char_u *line = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[lnum];
20972
d561e3c6cd65 patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents: 20966
diff changeset
2198 char_u *p;
d561e3c6cd65 patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents: 20966
diff changeset
2199
21767
9529a2367d3e patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents: 21763
diff changeset
2200 // ignore NULLs inserted for continuation lines
9529a2367d3e patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents: 21763
diff changeset
2201 if (line != NULL)
9529a2367d3e patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents: 21763
diff changeset
2202 {
9529a2367d3e patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents: 21763
diff changeset
2203 p = skipwhite(line);
9529a2367d3e patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents: 21763
diff changeset
2204 if (*p != NUL && !vim9_comment_start(p))
9529a2367d3e patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents: 21763
diff changeset
2205 return p;
9529a2367d3e patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents: 21763
diff changeset
2206 }
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2207 }
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2208 return NULL;
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2209 }
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2210
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2211 /*
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2212 * Called when checking for a following operator at "arg". When the rest of
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2213 * the line is empty or only a comment, peek the next line. If there is a next
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2214 * line return a pointer to it and set "nextp".
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2215 * Otherwise skip over white space.
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2216 */
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2217 static char_u *
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2218 may_peek_next_line(cctx_T *cctx, char_u *arg, char_u **nextp)
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2219 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2220 char_u *p = skipwhite(arg);
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2221
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2222 *nextp = NULL;
21353
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
2223 if (*p == NUL || (VIM_ISWHITE(*arg) && vim9_comment_start(p)))
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2224 {
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
2225 *nextp = peek_next_line_from_context(cctx);
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2226 if (*nextp != NULL)
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2227 return *nextp;
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2228 }
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2229 return p;
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2230 }
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2231
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2232 /*
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2233 * Get the next line of the function from "cctx".
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2234 * Skips over empty lines. Skips over comment lines if "skip_comment" is TRUE.
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2235 * Returns NULL when at the end.
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2236 */
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
2237 char_u *
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2238 next_line_from_context(cctx_T *cctx, int skip_comment)
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2239 {
20059
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20055
diff changeset
2240 char_u *line;
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2241
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2242 do
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2243 {
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2244 ++cctx->ctx_lnum;
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2245 if (cctx->ctx_lnum >= cctx->ctx_ufunc->uf_lines.ga_len)
20059
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20055
diff changeset
2246 {
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20055
diff changeset
2247 line = NULL;
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2248 break;
20059
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20055
diff changeset
2249 }
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2250 line = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum];
20059
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20055
diff changeset
2251 cctx->ctx_line_start = line;
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
2252 SOURCING_LNUM = cctx->ctx_lnum + 1;
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2253 } while (line == NULL || *skipwhite(line) == NUL
21689
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21683
diff changeset
2254 || (skip_comment && vim9_comment_start(skipwhite(line))));
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2255 return line;
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2256 }
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2257
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2258 /*
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
2259 * Skip over white space at "whitep" and assign to "*arg".
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2260 * If "*arg" is at the end of the line, advance to the next line.
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
2261 * Also when "whitep" points to white space and "*arg" is on a "#".
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2262 * Return FAIL if beyond the last line, "*arg" is unmodified then.
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2263 */
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2264 static int
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
2265 may_get_next_line(char_u *whitep, char_u **arg, cctx_T *cctx)
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2266 {
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
2267 *arg = skipwhite(whitep);
21353
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
2268 if (**arg == NUL || (VIM_ISWHITE(*whitep) && vim9_comment_start(*arg)))
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2269 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2270 char_u *next = next_line_from_context(cctx, TRUE);
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2271
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2272 if (next == NULL)
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2273 return FAIL;
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2274 *arg = skipwhite(next);
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2275 }
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2276 return OK;
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2277 }
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2278
21248
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2279 /*
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2280 * Idem, and give an error when failed.
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2281 */
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2282 static int
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2283 may_get_next_line_error(char_u *whitep, char_u **arg, cctx_T *cctx)
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2284 {
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2285 if (may_get_next_line(whitep, arg, cctx) == FAIL)
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2286 {
23122
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23114
diff changeset
2287 SOURCING_LNUM = cctx->ctx_lnum + 1;
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2288 emsg(_(e_line_incomplete));
21248
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2289 return FAIL;
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2290 }
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2291 return OK;
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2292 }
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2293
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2294
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2295 // Structure passed between the compile_expr* functions to keep track of
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2296 // constants that have been parsed but for which no code was produced yet. If
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2297 // possible expressions on these constants are applied at compile time. If
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2298 // that is not possible, the code to push the constants needs to be generated
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2299 // before other instructions.
20336
2fd980fb9ab3 patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents: 20334
diff changeset
2300 // Using 50 should be more than enough of 5 levels of ().
2fd980fb9ab3 patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents: 20334
diff changeset
2301 #define PPSIZE 50
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2302 typedef struct {
20336
2fd980fb9ab3 patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents: 20334
diff changeset
2303 typval_T pp_tv[PPSIZE]; // stack of ppconst constants
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2304 int pp_used; // active entries in pp_tv[]
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
2305 int pp_is_const; // all generated code was constants, used for a
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
2306 // list or dict with constant members
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2307 } ppconst_T;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2308
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
2309 static int compile_expr0_ext(char_u **arg, cctx_T *cctx, int *is_const);
20336
2fd980fb9ab3 patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents: 20334
diff changeset
2310 static int compile_expr0(char_u **arg, cctx_T *cctx);
2fd980fb9ab3 patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents: 20334
diff changeset
2311 static int compile_expr1(char_u **arg, cctx_T *cctx, ppconst_T *ppconst);
2fd980fb9ab3 patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents: 20334
diff changeset
2312
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2313 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2314 * Generate a PUSH instruction for "tv".
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2315 * "tv" will be consumed or cleared.
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2316 * Nothing happens if "tv" is NULL or of type VAR_UNKNOWN;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2317 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2318 static int
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2319 generate_tv_PUSH(cctx_T *cctx, typval_T *tv)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2320 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2321 if (tv != NULL)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2322 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2323 switch (tv->v_type)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2324 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2325 case VAR_UNKNOWN:
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2326 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2327 case VAR_BOOL:
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2328 generate_PUSHBOOL(cctx, tv->vval.v_number);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2329 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2330 case VAR_SPECIAL:
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2331 generate_PUSHSPEC(cctx, tv->vval.v_number);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2332 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2333 case VAR_NUMBER:
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2334 generate_PUSHNR(cctx, tv->vval.v_number);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2335 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2336 #ifdef FEAT_FLOAT
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2337 case VAR_FLOAT:
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2338 generate_PUSHF(cctx, tv->vval.v_float);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2339 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2340 #endif
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2341 case VAR_BLOB:
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2342 generate_PUSHBLOB(cctx, tv->vval.v_blob);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2343 tv->vval.v_blob = NULL;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2344 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2345 case VAR_STRING:
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2346 generate_PUSHS(cctx, tv->vval.v_string);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2347 tv->vval.v_string = NULL;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2348 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2349 default:
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2350 iemsg("constant type not supported");
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2351 clear_tv(tv);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2352 return FAIL;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2353 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2354 tv->v_type = VAR_UNKNOWN;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2355 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2356 return OK;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2357 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2358
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2359 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2360 * Generate code for any ppconst entries.
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2361 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2362 static int
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2363 generate_ppconst(cctx_T *cctx, ppconst_T *ppconst)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2364 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2365 int i;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2366 int ret = OK;
20332
a407e243c55c patch 8.2.0721: Vim9: leaking memory when skipping
Bram Moolenaar <Bram@vim.org>
parents: 20328
diff changeset
2367 int save_skip = cctx->ctx_skip;
a407e243c55c patch 8.2.0721: Vim9: leaking memory when skipping
Bram Moolenaar <Bram@vim.org>
parents: 20328
diff changeset
2368
20907
4eeda7139133 patch 8.2.1005: Vim9: using TRUE/FALSE/MAYBE for ctx_skip is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20899
diff changeset
2369 cctx->ctx_skip = SKIP_NOT;
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2370 for (i = 0; i < ppconst->pp_used; ++i)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2371 if (generate_tv_PUSH(cctx, &ppconst->pp_tv[i]) == FAIL)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2372 ret = FAIL;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2373 ppconst->pp_used = 0;
20332
a407e243c55c patch 8.2.0721: Vim9: leaking memory when skipping
Bram Moolenaar <Bram@vim.org>
parents: 20328
diff changeset
2374 cctx->ctx_skip = save_skip;
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2375 return ret;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2376 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2377
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2378 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2379 * Clear ppconst constants. Used when failing.
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2380 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2381 static void
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2382 clear_ppconst(ppconst_T *ppconst)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2383 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2384 int i;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2385
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2386 for (i = 0; i < ppconst->pp_used; ++i)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2387 clear_tv(&ppconst->pp_tv[i]);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2388 ppconst->pp_used = 0;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2389 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2390
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2391 /*
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2392 * Generate an instruction to load script-local variable "name", without the
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2393 * leading "s:".
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2394 * Also finds imported variables.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2395 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2396 static int
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2397 compile_load_scriptvar(
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2398 cctx_T *cctx,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2399 char_u *name, // variable NUL terminated
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2400 char_u *start, // start of variable
19530
48e71f948360 patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
2401 char_u **end, // end of variable
48e71f948360 patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
2402 int error) // when TRUE may give error
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2403 {
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2404 scriptitem_T *si;
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2405 int idx;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2406 imported_T *import;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2407
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2408 if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2409 return FAIL;
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2410 si = SCRIPT_ITEM(current_sctx.sc_sid);
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2411 idx = get_script_item_idx(current_sctx.sc_sid, name, FALSE, cctx);
19451
b26e96f7c12f patch 8.2.0283: Vim9: failing to load script var not tested
Bram Moolenaar <Bram@vim.org>
parents: 19437
diff changeset
2412 if (idx == -1 || si->sn_version != SCRIPT_VERSION_VIM9)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2413 {
19451
b26e96f7c12f patch 8.2.0283: Vim9: failing to load script var not tested
Bram Moolenaar <Bram@vim.org>
parents: 19437
diff changeset
2414 // variable is not in sn_var_vals: old style script.
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
2415 return generate_OLDSCRIPT(cctx, ISN_LOADS, name, current_sctx.sc_sid,
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
2416 &t_any);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2417 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2418 if (idx >= 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2419 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2420 svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) + idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2421
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
2422 generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2423 current_sctx.sc_sid, idx, sv->sv_type);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2424 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2425 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2426
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
2427 import = find_imported(name, 0, cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2428 if (import != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2429 {
23364
17a0e32eefd4 patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents: 23362
diff changeset
2430 if (import->imp_flags & IMP_FLAGS_STAR)
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2431 {
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2432 char_u *p = skipwhite(*end);
21146
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2433 char_u *exp_name;
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2434 int cc;
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2435 ufunc_T *ufunc;
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2436 type_T *type;
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2437
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2438 // Used "import * as Name", need to lookup the member.
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2439 if (*p != '.')
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2440 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2441 semsg(_(e_expected_dot_after_name_str), start);
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2442 return FAIL;
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2443 }
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2444 ++p;
19818
c1c88b333481 patch 8.2.0465: Vim9: dead code and wrong return type
Bram Moolenaar <Bram@vim.org>
parents: 19785
diff changeset
2445 if (VIM_ISWHITE(*p))
c1c88b333481 patch 8.2.0465: Vim9: dead code and wrong return type
Bram Moolenaar <Bram@vim.org>
parents: 19785
diff changeset
2446 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2447 emsg(_(e_no_white_space_allowed_after_dot));
19818
c1c88b333481 patch 8.2.0465: Vim9: dead code and wrong return type
Bram Moolenaar <Bram@vim.org>
parents: 19785
diff changeset
2448 return FAIL;
c1c88b333481 patch 8.2.0465: Vim9: dead code and wrong return type
Bram Moolenaar <Bram@vim.org>
parents: 19785
diff changeset
2449 }
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2450
21146
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2451 // isolate one name
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2452 exp_name = p;
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2453 while (eval_isnamec(*p))
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2454 ++p;
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2455 cc = *p;
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2456 *p = NUL;
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2457
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2458 idx = find_exported(import->imp_sid, exp_name, &ufunc, &type, cctx);
21146
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2459 *p = cc;
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2460 p = skipwhite(p);
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2461
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2462 // TODO: what if it is a function?
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2463 if (idx < 0)
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2464 return FAIL;
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2465 *end = p;
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2466
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2467 generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2468 import->imp_sid,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2469 idx,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2470 type);
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2471 }
21473
8bcd1ee2630b patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
2472 else if (import->imp_funcname != NULL)
8bcd1ee2630b patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
2473 generate_PUSHFUNC(cctx, import->imp_funcname, import->imp_type);
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2474 else
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2475 generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2476 import->imp_sid,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2477 import->imp_var_vals_idx,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2478 import->imp_type);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2479 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2480 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2481
19530
48e71f948360 patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
2482 if (error)
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2483 semsg(_(e_item_not_found_str), name);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2484 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2485 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2486
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2487 static int
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2488 generate_funcref(cctx_T *cctx, char_u *name)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2489 {
20189
63cc54100ae4 patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents: 20174
diff changeset
2490 ufunc_T *ufunc = find_func(name, FALSE, cctx);
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2491
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2492 if (ufunc == NULL)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2493 return FAIL;
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2494
21469
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
2495 // Need to compile any default values to get the argument types.
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
2496 if (ufunc->uf_def_status == UF_TO_BE_COMPILED)
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
2497 if (compile_def_function(ufunc, TRUE, NULL) == FAIL)
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
2498 return FAIL;
21473
8bcd1ee2630b patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
2499 return generate_PUSHFUNC(cctx, ufunc->uf_name, ufunc->uf_func_type);
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2500 }
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2501
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2502 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2503 * Compile a variable name into a load instruction.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2504 * "end" points to just after the name.
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2505 * "is_expr" is TRUE when evaluating an expression, might be a funcref.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2506 * When "error" is FALSE do not give an error when not found.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2507 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2508 static int
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2509 compile_load(
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2510 char_u **arg,
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2511 char_u *end_arg,
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2512 cctx_T *cctx,
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2513 int is_expr,
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2514 int error)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2515 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2516 type_T *type;
21399
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2517 char_u *name = NULL;
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2518 char_u *end = end_arg;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2519 int res = FAIL;
19818
c1c88b333481 patch 8.2.0465: Vim9: dead code and wrong return type
Bram Moolenaar <Bram@vim.org>
parents: 19785
diff changeset
2520 int prev_called_emsg = called_emsg;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2521
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2522 if (*(*arg + 1) == ':')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2523 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2524 // load namespaced variable
19822
fc3cdc819d80 patch 8.2.0467: Vim9: some errors are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19818
diff changeset
2525 if (end <= *arg + 2)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2526 {
21399
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2527 isntype_T isn_type;
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2528
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2529 switch (**arg)
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2530 {
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2531 case 'g': isn_type = ISN_LOADGDICT; break;
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2532 case 'w': isn_type = ISN_LOADWDICT; break;
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2533 case 't': isn_type = ISN_LOADTDICT; break;
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2534 case 'b': isn_type = ISN_LOADBDICT; break;
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2535 default:
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2536 semsg(_(e_namespace_not_supported_str), *arg);
21399
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2537 goto theend;
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2538 }
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2539 if (generate_instr_type(cctx, isn_type, &t_dict_any) == NULL)
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2540 goto theend;
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2541 res = OK;
19822
fc3cdc819d80 patch 8.2.0467: Vim9: some errors are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19818
diff changeset
2542 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2543 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2544 {
21399
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2545 isntype_T isn_type = ISN_DROP;
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2546
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2547 name = vim_strnsave(*arg + 2, end - (*arg + 2));
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2548 if (name == NULL)
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2549 return FAIL;
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2550
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2551 switch (**arg)
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2552 {
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2553 case 'v': res = generate_LOADV(cctx, name, error);
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2554 break;
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2555 case 's': res = compile_load_scriptvar(cctx, name,
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2556 NULL, NULL, error);
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2557 break;
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
2558 case 'g': if (vim_strchr(name, AUTOLOAD_CHAR) == NULL)
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
2559 isn_type = ISN_LOADG;
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
2560 else
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
2561 {
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
2562 isn_type = ISN_LOADAUTO;
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
2563 vim_free(name);
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
2564 name = vim_strnsave(*arg, end - *arg);
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
2565 if (name == NULL)
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
2566 return FAIL;
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
2567 }
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
2568 break;
21399
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2569 case 'w': isn_type = ISN_LOADW; break;
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2570 case 't': isn_type = ISN_LOADT; break;
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2571 case 'b': isn_type = ISN_LOADB; break;
23106
b0c88aa0175b patch 8.2.2099: Vim9: some checks are not tested
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
2572 default: // cannot happen, just in case
b0c88aa0175b patch 8.2.2099: Vim9: some checks are not tested
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
2573 semsg(_(e_namespace_not_supported_str), *arg);
21399
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2574 goto theend;
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2575 }
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2576 if (isn_type != ISN_DROP)
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2577 {
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2578 // Global, Buffer-local, Window-local and Tabpage-local
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2579 // variables can be defined later, thus we don't check if it
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2580 // exists, give error at runtime.
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2581 res = generate_LOAD(cctx, isn_type, 0, name, &t_any);
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2582 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2583 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2584 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2585 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2586 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2587 size_t len = end - *arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2588 int idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2589 int gen_load = FALSE;
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
2590 int gen_load_outer = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2591
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2592 name = vim_strnsave(*arg, end - *arg);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2593 if (name == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2594 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2595
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2596 if (arg_exists(*arg, len, &idx, &type, &gen_load_outer, cctx) == OK)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2597 {
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
2598 if (!gen_load_outer)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
2599 gen_load = TRUE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2600 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2601 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2602 {
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
2603 lvar_T lvar;
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
2604
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
2605 if (lookup_local(*arg, len, &lvar, cctx) == OK)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2606 {
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
2607 type = lvar.lv_type;
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
2608 idx = lvar.lv_idx;
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
2609 if (lvar.lv_from_outer)
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
2610 gen_load_outer = TRUE;
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
2611 else
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
2612 gen_load = TRUE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2613 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2614 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2615 {
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2616 // "var" can be script-local even without using "s:" if it
21921
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
2617 // already exists in a Vim9 script or when it's imported.
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2618 if (script_var_exists(*arg, len, TRUE, cctx) == OK
21921
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
2619 || find_imported(name, 0, cctx) != NULL)
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
2620 res = compile_load_scriptvar(cctx, name, *arg, &end, FALSE);
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2621
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2622 // When evaluating an expression and the name starts with an
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2623 // uppercase letter or "x:" it can be a user defined function.
21921
e420f3cf60e2 patch 8.2.1510: using "var" in :def function may refer to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
2624 // TODO: this is just guessing
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2625 if (res == FAIL && is_expr
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2626 && (ASCII_ISUPPER(*name) || name[1] == ':'))
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2627 res = generate_funcref(cctx, name);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2628 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2629 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2630 if (gen_load)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2631 res = generate_LOAD(cctx, ISN_LOAD, idx, NULL, type);
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
2632 if (gen_load_outer)
21769
f37c1330b15c patch 8.2.1434: Vim9: crash when lambda uses outer function argument
Bram Moolenaar <Bram@vim.org>
parents: 21767
diff changeset
2633 {
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
2634 res = generate_LOAD(cctx, ISN_LOADOUTER, idx, NULL, type);
21769
f37c1330b15c patch 8.2.1434: Vim9: crash when lambda uses outer function argument
Bram Moolenaar <Bram@vim.org>
parents: 21767
diff changeset
2635 cctx->ctx_outer_used = TRUE;
f37c1330b15c patch 8.2.1434: Vim9: crash when lambda uses outer function argument
Bram Moolenaar <Bram@vim.org>
parents: 21767
diff changeset
2636 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2637 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2638
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2639 *arg = end;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2640
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2641 theend:
19818
c1c88b333481 patch 8.2.0465: Vim9: dead code and wrong return type
Bram Moolenaar <Bram@vim.org>
parents: 19785
diff changeset
2642 if (res == FAIL && error && called_emsg == prev_called_emsg)
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2643 semsg(_(e_variable_not_found_str), name);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2644 vim_free(name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2645 return res;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2646 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2647
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2648 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2649 * Compile the argument expressions.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2650 * "arg" points to just after the "(" and is advanced to after the ")"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2651 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2652 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2653 compile_arguments(char_u **arg, cctx_T *cctx, int *argcount)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2654 {
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
2655 char_u *p = *arg;
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
2656 char_u *whitep = *arg;
22341
fc3350a38389 patch 8.2.1719: Vim9: no error if comma is missing in between arguments
Bram Moolenaar <Bram@vim.org>
parents: 22326
diff changeset
2657 int must_end = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2658
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2659 for (;;)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2660 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2661 if (may_get_next_line(whitep, &p, cctx) == FAIL)
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2662 goto failret;
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2663 if (*p == ')')
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2664 {
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2665 *arg = p + 1;
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2666 return OK;
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2667 }
22341
fc3350a38389 patch 8.2.1719: Vim9: no error if comma is missing in between arguments
Bram Moolenaar <Bram@vim.org>
parents: 22326
diff changeset
2668 if (must_end)
fc3350a38389 patch 8.2.1719: Vim9: no error if comma is missing in between arguments
Bram Moolenaar <Bram@vim.org>
parents: 22326
diff changeset
2669 {
fc3350a38389 patch 8.2.1719: Vim9: no error if comma is missing in between arguments
Bram Moolenaar <Bram@vim.org>
parents: 22326
diff changeset
2670 semsg(_(e_missing_comma_before_argument_str), p);
fc3350a38389 patch 8.2.1719: Vim9: no error if comma is missing in between arguments
Bram Moolenaar <Bram@vim.org>
parents: 22326
diff changeset
2671 return FAIL;
fc3350a38389 patch 8.2.1719: Vim9: no error if comma is missing in between arguments
Bram Moolenaar <Bram@vim.org>
parents: 22326
diff changeset
2672 }
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2673
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2674 if (compile_expr0(&p, cctx) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2675 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2676 ++*argcount;
19437
5d34ae66118e patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents: 19423
diff changeset
2677
5d34ae66118e patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents: 19423
diff changeset
2678 if (*p != ',' && *skipwhite(p) == ',')
5d34ae66118e patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents: 19423
diff changeset
2679 {
21909
a211bca98bc3 patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents: 21903
diff changeset
2680 semsg(_(e_no_white_space_allowed_before_str), ",");
19437
5d34ae66118e patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents: 19423
diff changeset
2681 p = skipwhite(p);
5d34ae66118e patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents: 19423
diff changeset
2682 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2683 if (*p == ',')
19437
5d34ae66118e patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents: 19423
diff changeset
2684 {
5d34ae66118e patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents: 19423
diff changeset
2685 ++p;
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2686 if (*p != NUL && !VIM_ISWHITE(*p))
21909
a211bca98bc3 patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents: 21903
diff changeset
2687 semsg(_(e_white_space_required_after_str), ",");
19437
5d34ae66118e patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents: 19423
diff changeset
2688 }
22341
fc3350a38389 patch 8.2.1719: Vim9: no error if comma is missing in between arguments
Bram Moolenaar <Bram@vim.org>
parents: 22326
diff changeset
2689 else
fc3350a38389 patch 8.2.1719: Vim9: no error if comma is missing in between arguments
Bram Moolenaar <Bram@vim.org>
parents: 22326
diff changeset
2690 must_end = TRUE;
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
2691 whitep = p;
19437
5d34ae66118e patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents: 19423
diff changeset
2692 p = skipwhite(p);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2693 }
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
2694 failret:
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2695 emsg(_(e_missing_close));
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2696 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2697 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2698
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2699 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2700 * Compile a function call: name(arg1, arg2)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2701 * "arg" points to "name", "arg + varlen" to the "(".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2702 * "argcount_init" is 1 for "value->method()"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2703 * Instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2704 * EVAL arg1
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2705 * EVAL arg2
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2706 * BCALL / DCALL / UCALL
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2707 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2708 static int
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2709 compile_call(
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2710 char_u **arg,
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2711 size_t varlen,
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2712 cctx_T *cctx,
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2713 ppconst_T *ppconst,
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2714 int argcount_init)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2715 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2716 char_u *name = *arg;
19257
5aab9c306181 patch 8.2.0187: reduntant code
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
2717 char_u *p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2718 int argcount = argcount_init;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2719 char_u namebuf[100];
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
2720 char_u fname_buf[FLEN_FIXED + 1];
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
2721 char_u *tofree = NULL;
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
2722 int error = FCERR_NONE;
22914
54f796fb7cb2 patch 8.2.2004: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents: 22910
diff changeset
2723 ufunc_T *ufunc = NULL;
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
2724 int res = FAIL;
21753
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21751
diff changeset
2725 int is_autoload;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2726
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2727 // we can evaluate "has('name')" at compile time
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2728 if (varlen == 3 && STRNCMP(*arg, "has", 3) == 0)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2729 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2730 char_u *s = skipwhite(*arg + varlen + 1);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2731 typval_T argvars[2];
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2732
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2733 argvars[0].v_type = VAR_UNKNOWN;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2734 if (*s == '"')
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21116
diff changeset
2735 (void)eval_string(&s, &argvars[0], TRUE);
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2736 else if (*s == '\'')
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21116
diff changeset
2737 (void)eval_lit_string(&s, &argvars[0], TRUE);
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2738 s = skipwhite(s);
22842
f2fbbb72ff28 patch 8.2.1968: Vim9: has() assumes a feature does not change dynamically
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
2739 if (*s == ')' && argvars[0].v_type == VAR_STRING
f2fbbb72ff28 patch 8.2.1968: Vim9: has() assumes a feature does not change dynamically
Bram Moolenaar <Bram@vim.org>
parents: 22816
diff changeset
2740 && !dynamic_feature(argvars[0].vval.v_string))
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2741 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2742 typval_T *tv = &ppconst->pp_tv[ppconst->pp_used];
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2743
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2744 *arg = s + 1;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2745 argvars[1].v_type = VAR_UNKNOWN;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2746 tv->v_type = VAR_NUMBER;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2747 tv->vval.v_number = 0;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2748 f_has(argvars, tv);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2749 clear_tv(&argvars[0]);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2750 ++ppconst->pp_used;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2751 return OK;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2752 }
20332
a407e243c55c patch 8.2.0721: Vim9: leaking memory when skipping
Bram Moolenaar <Bram@vim.org>
parents: 20328
diff changeset
2753 clear_tv(&argvars[0]);
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2754 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2755
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2756 if (generate_ppconst(cctx, ppconst) == FAIL)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2757 return FAIL;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2758
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2759 if (varlen >= sizeof(namebuf))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2760 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2761 semsg(_(e_name_too_long_str), name);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2762 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2763 }
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
2764 vim_strncpy(namebuf, *arg, varlen);
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
2765 name = fname_trans_sid(namebuf, fname_buf, &tofree, &error);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2766
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2767 *arg = skipwhite(*arg + varlen + 1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2768 if (compile_arguments(arg, cctx, &argcount) == FAIL)
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
2769 goto theend;
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
2770
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
2771 is_autoload = vim_strchr(name, AUTOLOAD_CHAR) != NULL;
21753
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21751
diff changeset
2772 if (ASCII_ISLOWER(*name) && name[1] != ':' && !is_autoload)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2773 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2774 int idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2775
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2776 // builtin function
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
2777 idx = find_internal_func(name);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2778 if (idx >= 0)
22633
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
2779 {
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
2780 if (STRCMP(name, "add") == 0 && argcount == 2)
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
2781 {
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
2782 garray_T *stack = &cctx->ctx_type_stack;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
2783 type_T *type = ((type_T **)stack->ga_data)[
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
2784 stack->ga_len - 2];
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
2785
22772
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
2786 // add() can be compiled to instructions if we know the type
22633
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
2787 if (type->tt_type == VAR_LIST)
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
2788 {
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
2789 // inline "add(list, item)" so that the type can be checked
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
2790 res = generate_LISTAPPEND(cctx);
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
2791 idx = -1;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
2792 }
22637
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
2793 else if (type->tt_type == VAR_BLOB)
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
2794 {
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
2795 // inline "add(blob, nr)" so that the type can be checked
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
2796 res = generate_BLOBAPPEND(cctx);
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
2797 idx = -1;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
2798 }
22633
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
2799 }
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
2800
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
2801 if (idx >= 0)
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
2802 res = generate_BCALL(cctx, idx, argcount, argcount_init == 1);
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
2803 }
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2804 else
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2805 semsg(_(e_unknownfunc), namebuf);
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2806 goto theend;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2807 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2808
22910
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
2809 // An argument or local variable can be a function reference, this
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
2810 // overrules a function name.
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
2811 if (lookup_local(namebuf, varlen, NULL, cctx) == FAIL
22910
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
2812 && arg_exists(namebuf, varlen, NULL, NULL, NULL, cctx) != OK)
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
2813 {
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
2814 // If we can find the function by name generate the right call.
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
2815 // Skip global functions here, a local funcref takes precedence.
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
2816 ufunc = find_func(name, FALSE, cctx);
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
2817 if (ufunc != NULL && !func_is_global(ufunc))
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
2818 {
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
2819 res = generate_CALL(cctx, ufunc, argcount);
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
2820 goto theend;
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
2821 }
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
2822 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2823
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2824 // If the name is a variable, load it and use PCALL.
20079
336483164ca6 patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents: 20059
diff changeset
2825 // Not for g:Func(), we don't know if it is a variable or not.
21753
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21751
diff changeset
2826 // Not for eome#Func(), it will be loaded later.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2827 p = namebuf;
21753
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21751
diff changeset
2828 if (STRNCMP(namebuf, "g:", 2) != 0 && !is_autoload
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2829 && compile_load(&p, namebuf + varlen, cctx, FALSE, FALSE) == OK)
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
2830 {
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
2831 garray_T *stack = &cctx->ctx_type_stack;
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
2832 type_T *type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
2833
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
2834 res = generate_PCALL(cctx, argcount, namebuf, type, FALSE);
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
2835 goto theend;
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
2836 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2837
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2838 // If we can find a global function by name generate the right call.
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2839 if (ufunc != NULL)
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2840 {
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2841 res = generate_CALL(cctx, ufunc, argcount);
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2842 goto theend;
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2843 }
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
2844
20140
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20138
diff changeset
2845 // A global function may be defined only later. Need to figure out at
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
2846 // runtime. Also handles a FuncRef at runtime.
21753
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21751
diff changeset
2847 if (STRNCMP(namebuf, "g:", 2) == 0 || is_autoload)
20140
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20138
diff changeset
2848 res = generate_UCALL(cctx, name, argcount);
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20138
diff changeset
2849 else
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20138
diff changeset
2850 semsg(_(e_unknownfunc), namebuf);
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
2851
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
2852 theend:
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
2853 vim_free(tofree);
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
2854 return res;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2855 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2856
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2857 // like NAMESPACE_CHAR but with 'a' and 'l'.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2858 #define VIM9_NAMESPACE_CHAR (char_u *)"bgstvw"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2859
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2860 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2861 * Find the end of a variable or function name. Unlike find_name_end() this
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2862 * does not recognize magic braces.
22946
d3b26055bfa8 patch 8.2.2020: some compilers do not like the "namespace" argument
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
2863 * When "use_namespace" is TRUE recognize "b:", "s:", etc.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2864 * Return a pointer to just after the name. Equal to "arg" if there is no
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2865 * valid name.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2866 */
22936
00b0275ffe7f patch 8.2.2015: Vim9: literal dict #{} is not like any other language
Bram Moolenaar <Bram@vim.org>
parents: 22932
diff changeset
2867 char_u *
22946
d3b26055bfa8 patch 8.2.2020: some compilers do not like the "namespace" argument
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
2868 to_name_end(char_u *arg, int use_namespace)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2869 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2870 char_u *p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2871
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2872 // Quick check for valid starting character.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2873 if (!eval_isnamec1(*arg))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2874 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2875
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2876 for (p = arg + 1; *p != NUL && eval_isnamec(*p); MB_PTR_ADV(p))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2877 // Include a namespace such as "s:var" and "v:var". But "n:" is not
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2878 // and can be used in slice "[n:]".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2879 if (*p == ':' && (p != arg + 1
22946
d3b26055bfa8 patch 8.2.2020: some compilers do not like the "namespace" argument
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
2880 || !use_namespace
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2881 || vim_strchr(VIM9_NAMESPACE_CHAR, *arg) == NULL))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2882 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2883 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2884 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2885
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2886 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2887 * Like to_name_end() but also skip over a list or dict constant.
21146
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2888 * This intentionally does not handle line continuation.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2889 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2890 char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2891 to_name_const_end(char_u *arg)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2892 {
19583
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
2893 char_u *p = to_name_end(arg, TRUE);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2894 typval_T rettv;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2895
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2896 if (p == arg && *arg == '[')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2897 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2898
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2899 // Can be "[1, 2, 3]->Func()".
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21116
diff changeset
2900 if (eval_list(&p, &rettv, NULL, FALSE) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2901 p = arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2902 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2903 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2904 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2905
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2906 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2907 * parse a list: [expr, expr]
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2908 * "*arg" points to the '['.
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
2909 * ppconst->pp_is_const is set if all items are a constant.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2910 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2911 static int
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
2912 compile_list(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2913 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2914 char_u *p = skipwhite(*arg + 1);
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
2915 char_u *whitep = *arg + 1;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2916 int count = 0;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
2917 int is_const;
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
2918 int is_all_const = TRUE; // reset when non-const encountered
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2919
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
2920 for (;;)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2921 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2922 if (may_get_next_line(whitep, &p, cctx) == FAIL)
19830
6500dcaf8e1a patch 8.2.0471: missing change to compile_list()
Bram Moolenaar <Bram@vim.org>
parents: 19822
diff changeset
2923 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2924 semsg(_(e_list_end), *arg);
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2925 return FAIL;
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
2926 }
21761
5a2373c25a86 patch 8.2.1430: Vim9: error for missing comma instead of extra white space
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
2927 if (*p == ',')
5a2373c25a86 patch 8.2.1430: Vim9: error for missing comma instead of extra white space
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
2928 {
21909
a211bca98bc3 patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents: 21903
diff changeset
2929 semsg(_(e_no_white_space_allowed_before_str), ",");
21761
5a2373c25a86 patch 8.2.1430: Vim9: error for missing comma instead of extra white space
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
2930 return FAIL;
5a2373c25a86 patch 8.2.1430: Vim9: error for missing comma instead of extra white space
Bram Moolenaar <Bram@vim.org>
parents: 21759
diff changeset
2931 }
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
2932 if (*p == ']')
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
2933 {
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
2934 ++p;
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
2935 break;
19830
6500dcaf8e1a patch 8.2.0471: missing change to compile_list()
Bram Moolenaar <Bram@vim.org>
parents: 19822
diff changeset
2936 }
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
2937 if (compile_expr0_ext(&p, cctx, &is_const) == FAIL)
22482
a1b3804163ca patch 8.2.1789: Vim9: crash with invalid list constant
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
2938 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
2939 if (!is_const)
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
2940 is_all_const = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2941 ++count;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2942 if (*p == ',')
21216
bcd08812cde3 patch 8.2.1159: Vim9: no error for missing space after a comma
Bram Moolenaar <Bram@vim.org>
parents: 21210
diff changeset
2943 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2944 ++p;
21216
bcd08812cde3 patch 8.2.1159: Vim9: no error for missing space after a comma
Bram Moolenaar <Bram@vim.org>
parents: 21210
diff changeset
2945 if (*p != ']' && !IS_WHITE_OR_NUL(*p))
bcd08812cde3 patch 8.2.1159: Vim9: no error for missing space after a comma
Bram Moolenaar <Bram@vim.org>
parents: 21210
diff changeset
2946 {
21909
a211bca98bc3 patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents: 21903
diff changeset
2947 semsg(_(e_white_space_required_after_str), ",");
21216
bcd08812cde3 patch 8.2.1159: Vim9: no error for missing space after a comma
Bram Moolenaar <Bram@vim.org>
parents: 21210
diff changeset
2948 return FAIL;
bcd08812cde3 patch 8.2.1159: Vim9: no error for missing space after a comma
Bram Moolenaar <Bram@vim.org>
parents: 21210
diff changeset
2949 }
bcd08812cde3 patch 8.2.1159: Vim9: no error for missing space after a comma
Bram Moolenaar <Bram@vim.org>
parents: 21210
diff changeset
2950 }
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
2951 whitep = p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2952 p = skipwhite(p);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2953 }
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
2954 *arg = p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2955
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
2956 ppconst->pp_is_const = is_all_const;
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
2957 return generate_NEWLIST(cctx, count);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2958 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2959
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2960 /*
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
2961 * Parse a lambda: "(arg, arg) => expr"
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2962 * "*arg" points to the '{'.
23368
a7cbdb9294c4 patch 8.2.2227: Vim9: recognizing lambda is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 23364
diff changeset
2963 * Returns OK/FAIL when a lambda is recognized, NOTDONE if it's not a lambda.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2964 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2965 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2966 compile_lambda(char_u **arg, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2967 {
23368
a7cbdb9294c4 patch 8.2.2227: Vim9: recognizing lambda is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 23364
diff changeset
2968 int r;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2969 typval_T rettv;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2970 ufunc_T *ufunc;
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
2971 evalarg_T evalarg;
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
2972
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
2973 CLEAR_FIELD(evalarg);
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
2974 evalarg.eval_flags = EVAL_EVALUATE;
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
2975 evalarg.eval_cctx = cctx;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2976
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2977 // Get the funcref in "rettv".
23368
a7cbdb9294c4 patch 8.2.2227: Vim9: recognizing lambda is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 23364
diff changeset
2978 r = get_lambda_tv(arg, &rettv, TRUE, &evalarg);
a7cbdb9294c4 patch 8.2.2227: Vim9: recognizing lambda is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 23364
diff changeset
2979 if (r != OK)
22627
1064b9f05b0a patch 8.2.1862: vim9: memory leak when compiling lambda fails
Bram Moolenaar <Bram@vim.org>
parents: 22614
diff changeset
2980 {
1064b9f05b0a patch 8.2.1862: vim9: memory leak when compiling lambda fails
Bram Moolenaar <Bram@vim.org>
parents: 22614
diff changeset
2981 clear_evalarg(&evalarg, NULL);
23368
a7cbdb9294c4 patch 8.2.2227: Vim9: recognizing lambda is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 23364
diff changeset
2982 return r;
22627
1064b9f05b0a patch 8.2.1862: vim9: memory leak when compiling lambda fails
Bram Moolenaar <Bram@vim.org>
parents: 22614
diff changeset
2983 }
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2984
23318
c76240efdf02 patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents: 23310
diff changeset
2985 // "rettv" will now be a partial referencing the function.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2986 ufunc = rettv.vval.v_partial->pt_func;
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2987 ++ufunc->uf_refcount;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2988 clear_tv(&rettv);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2989
23318
c76240efdf02 patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents: 23310
diff changeset
2990 // Compile the function into instructions.
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
2991 compile_def_function(ufunc, TRUE, cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2992
21220
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21218
diff changeset
2993 clear_evalarg(&evalarg, NULL);
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21218
diff changeset
2994
20943
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
2995 if (ufunc->uf_def_status == UF_COMPILED)
21693
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
2996 {
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
2997 // The return type will now be known.
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
2998 set_function_type(ufunc);
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
2999
22324
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
3000 // The function reference count will be 1. When the ISN_FUNCREF
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
3001 // instruction is deleted the reference count is decremented and the
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
3002 // function is freed.
21693
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
3003 return generate_FUNCREF(cctx, ufunc);
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
3004 }
21353
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
3005
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
3006 func_ptr_unref(ufunc);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3007 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3008 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3009
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3010 /*
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
3011 * parse a dict: {key: val, [key]: val}
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3012 * "*arg" points to the '{'.
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3013 * ppconst->pp_is_const is set if all item values are a constant.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3014 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3015 static int
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
3016 compile_dict(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3017 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3018 garray_T *instr = &cctx->ctx_instr;
21301
60011b87aae1 patch 8.2.1201: Vim9: crash when passing number as dict key
Bram Moolenaar <Bram@vim.org>
parents: 21281
diff changeset
3019 garray_T *stack = &cctx->ctx_type_stack;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3020 int count = 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3021 dict_T *d = dict_alloc();
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3022 dictitem_T *item;
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
3023 char_u *whitep = *arg + 1;
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3024 char_u *p;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3025 int is_const;
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3026 int is_all_const = TRUE; // reset when non-const encountered
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3027
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3028 if (d == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3029 return FAIL;
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3030 for (;;)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3031 {
22936
00b0275ffe7f patch 8.2.2015: Vim9: literal dict #{} is not like any other language
Bram Moolenaar <Bram@vim.org>
parents: 22932
diff changeset
3032 char_u *key = NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3033
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3034 if (may_get_next_line(whitep, arg, cctx) == FAIL)
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3035 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3036 *arg = NULL;
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3037 goto failret;
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3038 }
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3039
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3040 if (**arg == '}')
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3041 break;
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3042
23088
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3043 if (**arg == '[')
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3044 {
22936
00b0275ffe7f patch 8.2.2015: Vim9: literal dict #{} is not like any other language
Bram Moolenaar <Bram@vim.org>
parents: 22932
diff changeset
3045 isn_T *isn;
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
3046
23088
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3047 // {[expr]: value} uses an evaluated key.
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
3048 *arg = skipwhite(*arg + 1);
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3049 if (compile_expr0(arg, cctx) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3050 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3051 isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3052 if (isn->isn_type == ISN_PUSHS)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3053 key = isn->isn_arg.string;
21301
60011b87aae1 patch 8.2.1201: Vim9: crash when passing number as dict key
Bram Moolenaar <Bram@vim.org>
parents: 21281
diff changeset
3054 else
60011b87aae1 patch 8.2.1201: Vim9: crash when passing number as dict key
Bram Moolenaar <Bram@vim.org>
parents: 21281
diff changeset
3055 {
60011b87aae1 patch 8.2.1201: Vim9: crash when passing number as dict key
Bram Moolenaar <Bram@vim.org>
parents: 21281
diff changeset
3056 type_T *keytype = ((type_T **)stack->ga_data)
22936
00b0275ffe7f patch 8.2.2015: Vim9: literal dict #{} is not like any other language
Bram Moolenaar <Bram@vim.org>
parents: 22932
diff changeset
3057 [stack->ga_len - 1];
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3058 if (need_type(keytype, &t_string, -1, cctx,
22936
00b0275ffe7f patch 8.2.2015: Vim9: literal dict #{} is not like any other language
Bram Moolenaar <Bram@vim.org>
parents: 22932
diff changeset
3059 FALSE, FALSE) == FAIL)
21301
60011b87aae1 patch 8.2.1201: Vim9: crash when passing number as dict key
Bram Moolenaar <Bram@vim.org>
parents: 21281
diff changeset
3060 return FAIL;
60011b87aae1 patch 8.2.1201: Vim9: crash when passing number as dict key
Bram Moolenaar <Bram@vim.org>
parents: 21281
diff changeset
3061 }
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
3062 *arg = skipwhite(*arg);
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
3063 if (**arg != ']')
22936
00b0275ffe7f patch 8.2.2015: Vim9: literal dict #{} is not like any other language
Bram Moolenaar <Bram@vim.org>
parents: 22932
diff changeset
3064 {
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
3065 emsg(_(e_missing_matching_bracket_after_dict_key));
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
3066 return FAIL;
22936
00b0275ffe7f patch 8.2.2015: Vim9: literal dict #{} is not like any other language
Bram Moolenaar <Bram@vim.org>
parents: 22932
diff changeset
3067 }
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
3068 ++*arg;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3069 }
23088
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3070 else
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3071 {
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3072 // {"name": value},
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3073 // {'name': value},
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3074 // {name: value} use "name" as a literal key
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3075 key = get_literal_key(arg);
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3076 if (key == NULL)
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3077 return FAIL;
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3078 if (generate_PUSHS(cctx, key) == FAIL)
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3079 return FAIL;
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3080 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3081
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3082 // Check for duplicate keys, if using string keys.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3083 if (key != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3084 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3085 item = dict_find(d, key, -1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3086 if (item != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3087 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3088 semsg(_(e_duplicate_key), key);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3089 goto failret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3090 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3091 item = dictitem_alloc(key);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3092 if (item != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3093 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3094 item->di_tv.v_type = VAR_UNKNOWN;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3095 item->di_tv.v_lock = 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3096 if (dict_add(d, item) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3097 dictitem_free(item);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3098 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3099 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3100
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3101 if (**arg != ':')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3102 {
21759
25b659fa5ca5 patch 8.2.1429: Vim9: no error for missing white after : in dict
Bram Moolenaar <Bram@vim.org>
parents: 21755
diff changeset
3103 if (*skipwhite(*arg) == ':')
21909
a211bca98bc3 patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents: 21903
diff changeset
3104 semsg(_(e_no_white_space_allowed_before_str), ":");
21759
25b659fa5ca5 patch 8.2.1429: Vim9: no error for missing white after : in dict
Bram Moolenaar <Bram@vim.org>
parents: 21755
diff changeset
3105 else
25b659fa5ca5 patch 8.2.1429: Vim9: no error for missing white after : in dict
Bram Moolenaar <Bram@vim.org>
parents: 21755
diff changeset
3106 semsg(_(e_missing_dict_colon), *arg);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3107 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3108 }
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3109 whitep = *arg + 1;
21759
25b659fa5ca5 patch 8.2.1429: Vim9: no error for missing white after : in dict
Bram Moolenaar <Bram@vim.org>
parents: 21755
diff changeset
3110 if (!IS_WHITE_OR_NUL(*whitep))
25b659fa5ca5 patch 8.2.1429: Vim9: no error for missing white after : in dict
Bram Moolenaar <Bram@vim.org>
parents: 21755
diff changeset
3111 {
21909
a211bca98bc3 patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents: 21903
diff changeset
3112 semsg(_(e_white_space_required_after_str), ":");
21759
25b659fa5ca5 patch 8.2.1429: Vim9: no error for missing white after : in dict
Bram Moolenaar <Bram@vim.org>
parents: 21755
diff changeset
3113 return FAIL;
25b659fa5ca5 patch 8.2.1429: Vim9: no error for missing white after : in dict
Bram Moolenaar <Bram@vim.org>
parents: 21755
diff changeset
3114 }
25b659fa5ca5 patch 8.2.1429: Vim9: no error for missing white after : in dict
Bram Moolenaar <Bram@vim.org>
parents: 21755
diff changeset
3115
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3116 if (may_get_next_line(whitep, arg, cctx) == FAIL)
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3117 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3118 *arg = NULL;
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3119 goto failret;
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3120 }
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3121
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3122 if (compile_expr0_ext(arg, cctx, &is_const) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3123 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3124 if (!is_const)
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3125 is_all_const = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3126 ++count;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3127
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3128 whitep = *arg;
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3129 if (may_get_next_line(whitep, arg, cctx) == FAIL)
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3130 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3131 *arg = NULL;
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3132 goto failret;
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3133 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3134 if (**arg == '}')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3135 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3136 if (**arg != ',')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3137 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3138 semsg(_(e_missing_dict_comma), *arg);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3139 goto failret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3140 }
21763
703ea7603d3e patch 8.2.1431: Vim9: no error for white space before comma in dict
Bram Moolenaar <Bram@vim.org>
parents: 21761
diff changeset
3141 if (IS_WHITE_OR_NUL(*whitep))
703ea7603d3e patch 8.2.1431: Vim9: no error for white space before comma in dict
Bram Moolenaar <Bram@vim.org>
parents: 21761
diff changeset
3142 {
21909
a211bca98bc3 patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents: 21903
diff changeset
3143 semsg(_(e_no_white_space_allowed_before_str), ",");
21763
703ea7603d3e patch 8.2.1431: Vim9: no error for white space before comma in dict
Bram Moolenaar <Bram@vim.org>
parents: 21761
diff changeset
3144 return FAIL;
703ea7603d3e patch 8.2.1431: Vim9: no error for white space before comma in dict
Bram Moolenaar <Bram@vim.org>
parents: 21761
diff changeset
3145 }
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3146 whitep = *arg + 1;
22639
5bd53bf63836 patch 8.2.1868: Vim9: no error for missing space after comma in dict
Bram Moolenaar <Bram@vim.org>
parents: 22637
diff changeset
3147 if (!IS_WHITE_OR_NUL(*whitep))
5bd53bf63836 patch 8.2.1868: Vim9: no error for missing space after comma in dict
Bram Moolenaar <Bram@vim.org>
parents: 22637
diff changeset
3148 {
5bd53bf63836 patch 8.2.1868: Vim9: no error for missing space after comma in dict
Bram Moolenaar <Bram@vim.org>
parents: 22637
diff changeset
3149 semsg(_(e_white_space_required_after_str), ",");
5bd53bf63836 patch 8.2.1868: Vim9: no error for missing space after comma in dict
Bram Moolenaar <Bram@vim.org>
parents: 22637
diff changeset
3150 return FAIL;
5bd53bf63836 patch 8.2.1868: Vim9: no error for missing space after comma in dict
Bram Moolenaar <Bram@vim.org>
parents: 22637
diff changeset
3151 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3152 *arg = skipwhite(*arg + 1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3153 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3154
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3155 *arg = *arg + 1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3156
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3157 // Allow for following comment, after at least one space.
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3158 p = skipwhite(*arg);
21353
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
3159 if (VIM_ISWHITE(**arg) && vim9_comment_start(p))
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3160 *arg += STRLEN(*arg);
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3161
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3162 dict_unref(d);
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3163 ppconst->pp_is_const = is_all_const;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3164 return generate_NEWDICT(cctx, count);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3165
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3166 failret:
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3167 if (*arg == NULL)
22508
ac8c4a8b8cba patch 8.2.1802: Vim9: crash with unterminated dict
Bram Moolenaar <Bram@vim.org>
parents: 22504
diff changeset
3168 {
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3169 semsg(_(e_missing_dict_end), _("[end of lines]"));
22508
ac8c4a8b8cba patch 8.2.1802: Vim9: crash with unterminated dict
Bram Moolenaar <Bram@vim.org>
parents: 22504
diff changeset
3170 *arg = (char_u *)"";
ac8c4a8b8cba patch 8.2.1802: Vim9: crash with unterminated dict
Bram Moolenaar <Bram@vim.org>
parents: 22504
diff changeset
3171 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3172 dict_unref(d);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3173 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3174 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3175
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3176 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3177 * Compile "&option".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3178 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3179 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3180 compile_get_option(char_u **arg, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3181 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3182 typval_T rettv;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3183 char_u *start = *arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3184 int ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3185
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3186 // parse the option and get the current value to get the type.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3187 rettv.v_type = VAR_UNKNOWN;
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21116
diff changeset
3188 ret = eval_option(arg, &rettv, TRUE);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3189 if (ret == OK)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3190 {
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21116
diff changeset
3191 // include the '&' in the name, eval_option() expects it.
23436
ab163feb30cb patch 8.2.2261: Vim9: boolean option gets string type
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
3192 char_u *name = vim_strnsave(start, *arg - start);
ab163feb30cb patch 8.2.2261: Vim9: boolean option gets string type
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
3193 type_T *type = rettv.v_type == VAR_BOOL ? &t_bool
ab163feb30cb patch 8.2.2261: Vim9: boolean option gets string type
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
3194 : rettv.v_type == VAR_NUMBER ? &t_number : &t_string;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3195
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3196 ret = generate_LOAD(cctx, ISN_LOADOPT, 0, name, type);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3197 vim_free(name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3198 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3199 clear_tv(&rettv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3200
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3201 return ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3202 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3203
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3204 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3205 * Compile "$VAR".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3206 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3207 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3208 compile_get_env(char_u **arg, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3209 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3210 char_u *start = *arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3211 int len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3212 int ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3213 char_u *name;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3214
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3215 ++*arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3216 len = get_env_len(arg);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3217 if (len == 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3218 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
3219 semsg(_(e_syntax_error_at_str), start - 1);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3220 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3221 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3222
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21116
diff changeset
3223 // include the '$' in the name, eval_env_var() expects it.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3224 name = vim_strnsave(start, len + 1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3225 ret = generate_LOAD(cctx, ISN_LOADENV, 0, name, &t_string);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3226 vim_free(name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3227 return ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3228 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3229
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3230 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3231 * Compile "@r".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3232 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3233 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3234 compile_get_register(char_u **arg, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3235 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3236 int ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3237
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3238 ++*arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3239 if (**arg == NUL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3240 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
3241 semsg(_(e_syntax_error_at_str), *arg - 1);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3242 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3243 }
21612
c495d3e30f4b patch 8.2.1356: Vim9: cannot get the percent register
Bram Moolenaar <Bram@vim.org>
parents: 21610
diff changeset
3244 if (!valid_yank_reg(**arg, FALSE))
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3245 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3246 emsg_invreg(**arg);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3247 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3248 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3249 ret = generate_LOAD(cctx, ISN_LOADREG, **arg, NULL, &t_string);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3250 ++*arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3251 return ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3252 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3253
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3254 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3255 * Apply leading '!', '-' and '+' to constant "rettv".
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3256 * When "numeric_only" is TRUE do not apply '!'.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3257 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3258 static int
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3259 apply_leader(typval_T *rettv, int numeric_only, char_u *start, char_u **end)
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3260 {
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3261 char_u *p = *end;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3262
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3263 // this works from end to start
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3264 while (p > start)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3265 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3266 --p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3267 if (*p == '-' || *p == '+')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3268 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3269 // only '-' has an effect, for '+' we only check the type
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3270 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3271 if (rettv->v_type == VAR_FLOAT)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3272 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3273 if (*p == '-')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3274 rettv->vval.v_float = -rettv->vval.v_float;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3275 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3276 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3277 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3278 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3279 varnumber_T val;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3280 int error = FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3281
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3282 // tv_get_number_chk() accepts a string, but we don't want that
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3283 // here
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3284 if (check_not_string(rettv) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3285 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3286 val = tv_get_number_chk(rettv, &error);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3287 clear_tv(rettv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3288 if (error)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3289 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3290 if (*p == '-')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3291 val = -val;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3292 rettv->v_type = VAR_NUMBER;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3293 rettv->vval.v_number = val;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3294 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3295 }
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3296 else if (numeric_only)
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3297 {
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3298 ++p;
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3299 break;
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3300 }
22606
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
3301 else if (*p == '!')
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3302 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3303 int v = tv2bool(rettv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3304
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3305 // '!' is permissive in the type.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3306 clear_tv(rettv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3307 rettv->v_type = VAR_BOOL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3308 rettv->vval.v_number = v ? VVAL_FALSE : VVAL_TRUE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3309 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3310 }
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3311 *end = p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3312 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3313 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3314
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3315 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3316 * Recognize v: variables that are constants and set "rettv".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3317 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3318 static void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3319 get_vim_constant(char_u **arg, typval_T *rettv)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3320 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3321 if (STRNCMP(*arg, "v:true", 6) == 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3322 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3323 rettv->v_type = VAR_BOOL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3324 rettv->vval.v_number = VVAL_TRUE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3325 *arg += 6;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3326 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3327 else if (STRNCMP(*arg, "v:false", 7) == 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3328 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3329 rettv->v_type = VAR_BOOL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3330 rettv->vval.v_number = VVAL_FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3331 *arg += 7;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3332 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3333 else if (STRNCMP(*arg, "v:null", 6) == 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3334 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3335 rettv->v_type = VAR_SPECIAL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3336 rettv->vval.v_number = VVAL_NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3337 *arg += 6;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3338 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3339 else if (STRNCMP(*arg, "v:none", 6) == 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3340 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3341 rettv->v_type = VAR_SPECIAL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3342 rettv->vval.v_number = VVAL_NONE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3343 *arg += 6;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3344 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3345 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3346
21546
4d3e983313dc patch 8.2.1323: Vim9: invalid operators only rejected in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21540
diff changeset
3347 exptype_T
20305
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3348 get_compare_type(char_u *p, int *len, int *type_is)
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3349 {
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3350 exptype_T type = EXPR_UNKNOWN;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3351 int i;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3352
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3353 switch (p[0])
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3354 {
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3355 case '=': if (p[1] == '=')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3356 type = EXPR_EQUAL;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3357 else if (p[1] == '~')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3358 type = EXPR_MATCH;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3359 break;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3360 case '!': if (p[1] == '=')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3361 type = EXPR_NEQUAL;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3362 else if (p[1] == '~')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3363 type = EXPR_NOMATCH;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3364 break;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3365 case '>': if (p[1] != '=')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3366 {
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3367 type = EXPR_GREATER;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3368 *len = 1;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3369 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3370 else
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3371 type = EXPR_GEQUAL;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3372 break;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3373 case '<': if (p[1] != '=')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3374 {
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3375 type = EXPR_SMALLER;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3376 *len = 1;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3377 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3378 else
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3379 type = EXPR_SEQUAL;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3380 break;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3381 case 'i': if (p[1] == 's')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3382 {
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3383 // "is" and "isnot"; but not a prefix of a name
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3384 if (p[2] == 'n' && p[3] == 'o' && p[4] == 't')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3385 *len = 5;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3386 i = p[*len];
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3387 if (!isalnum(i) && i != '_')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3388 {
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3389 type = *len == 2 ? EXPR_IS : EXPR_ISNOT;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3390 *type_is = TRUE;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3391 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3392 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3393 break;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3394 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3395 return type;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3396 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3397
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3398 /*
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3399 * Skip over an expression, ignoring most errors.
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3400 */
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3401 static void
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3402 skip_expr_cctx(char_u **arg, cctx_T *cctx)
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3403 {
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3404 evalarg_T evalarg;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3405
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3406 CLEAR_FIELD(evalarg);
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3407 evalarg.eval_cctx = cctx;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3408 skip_expr(arg, &evalarg);
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3409 }
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3410
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3411 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3412 * Compile code to apply '-', '+' and '!'.
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3413 * When "numeric_only" is TRUE do not apply '!'.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3414 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3415 static int
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3416 compile_leader(cctx_T *cctx, int numeric_only, char_u *start, char_u **end)
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3417 {
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3418 char_u *p = *end;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3419
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3420 // this works from end to start
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3421 while (p > start)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3422 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3423 --p;
22932
87b62395a4d1 patch 8.2.2013: Vim9: not skipping white space after unary minus
Bram Moolenaar <Bram@vim.org>
parents: 22926
diff changeset
3424 while (VIM_ISWHITE(*p))
87b62395a4d1 patch 8.2.2013: Vim9: not skipping white space after unary minus
Bram Moolenaar <Bram@vim.org>
parents: 22926
diff changeset
3425 --p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3426 if (*p == '-' || *p == '+')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3427 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3428 int negate = *p == '-';
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3429 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3430
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3431 // TODO: check type
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3432 while (p > start && (p[-1] == '-' || p[-1] == '+'))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3433 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3434 --p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3435 if (*p == '-')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3436 negate = !negate;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3437 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3438 // only '-' has an effect, for '+' we only check the type
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3439 if (negate)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3440 isn = generate_instr(cctx, ISN_NEGATENR);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3441 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3442 isn = generate_instr(cctx, ISN_CHECKNR);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3443 if (isn == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3444 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3445 }
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3446 else if (numeric_only)
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3447 {
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3448 ++p;
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3449 break;
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3450 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3451 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3452 {
22606
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
3453 int invert = *p == '!';
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
3454
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
3455 while (p > start && (p[-1] == '!' || VIM_ISWHITE(p[-1])))
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3456 {
22606
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
3457 if (p[-1] == '!')
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
3458 invert = !invert;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3459 --p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3460 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3461 if (generate_2BOOL(cctx, invert) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3462 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3463 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3464 }
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3465 *end = p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3466 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3467 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3468
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3469 /*
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3470 * Compile "(expression)": recursive!
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3471 * Return FAIL/OK.
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3472 */
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3473 static int
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3474 compile_parenthesis(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3475 {
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
3476 int ret;
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3477
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3478 *arg = skipwhite(*arg + 1);
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3479 if (ppconst->pp_used <= PPSIZE - 10)
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3480 {
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3481 ret = compile_expr1(arg, cctx, ppconst);
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3482 }
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3483 else
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3484 {
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3485 // Not enough space in ppconst, flush constants.
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3486 if (generate_ppconst(cctx, ppconst) == FAIL)
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3487 return FAIL;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3488 ret = compile_expr0(arg, cctx);
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3489 }
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
3490 if (may_get_next_line_error(*arg, arg, cctx) == FAIL)
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
3491 return FAIL;
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3492 if (**arg == ')')
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3493 ++*arg;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3494 else if (ret == OK)
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3495 {
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3496 emsg(_(e_missing_close));
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3497 ret = FAIL;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3498 }
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3499 return ret;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3500 }
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3501
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3502 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3503 * Compile whatever comes after "name" or "name()".
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
3504 * Advances "*arg" only when something was recognized.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3505 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3506 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3507 compile_subscript(
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3508 char_u **arg,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3509 cctx_T *cctx,
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3510 char_u *start_leader,
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3511 char_u **end_leader,
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
3512 ppconst_T *ppconst)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3513 {
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3514 char_u *name_start = *end_leader;
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3515
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3516 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3517 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3518 char_u *p = skipwhite(*arg);
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3519
21353
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
3520 if (*p == NUL || (VIM_ISWHITE(**arg) && vim9_comment_start(p)))
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3521 {
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
3522 char_u *next = peek_next_line_from_context(cctx);
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3523
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3524 // If a following line starts with "->{" or "->X" advance to that
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3525 // line, so that a line break before "->" is allowed.
21248
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
3526 // Also if a following line starts with ".x".
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
3527 if (next != NULL &&
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
3528 ((next[0] == '-' && next[1] == '>'
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
3529 && (next[2] == '{' || ASCII_ISALPHA(next[2])))
21512
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21504
diff changeset
3530 || (next[0] == '.' && eval_isdictc(next[1]))))
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3531 {
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3532 next = next_line_from_context(cctx, TRUE);
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3533 if (next == NULL)
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3534 return FAIL;
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
3535 *arg = next;
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
3536 p = skipwhite(*arg);
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3537 }
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3538 }
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3539
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 23199
diff changeset
3540 // Do not skip over white space to find the "(", "execute 'x' ()" is
21485
afc8cc1a291f patch 8.2.1293: Vim9: error when using vim9script in TextYankPost
Bram Moolenaar <Bram@vim.org>
parents: 21473
diff changeset
3541 // not a function call.
afc8cc1a291f patch 8.2.1293: Vim9: error when using vim9script in TextYankPost
Bram Moolenaar <Bram@vim.org>
parents: 21473
diff changeset
3542 if (**arg == '(')
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3543 {
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
3544 garray_T *stack = &cctx->ctx_type_stack;
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
3545 type_T *type;
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
3546 int argcount = 0;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3547
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
3548 if (generate_ppconst(cctx, ppconst) == FAIL)
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
3549 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3550 ppconst->pp_is_const = FALSE;
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
3551
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3552 // funcref(arg)
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
3553 type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
3554
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
3555 *arg = skipwhite(p + 1);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3556 if (compile_arguments(arg, cctx, &argcount) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3557 return FAIL;
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3558 if (generate_PCALL(cctx, argcount, name_start, type, TRUE) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3559 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3560 }
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
3561 else if (*p == '-' && p[1] == '>')
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3562 {
21465
b5d4ab124782 patch 8.2.1283: Vim9: error for misplaced -> lacks argument
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
3563 char_u *pstart = p;
b5d4ab124782 patch 8.2.1283: Vim9: error for misplaced -> lacks argument
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
3564
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
3565 if (generate_ppconst(cctx, ppconst) == FAIL)
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
3566 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3567 ppconst->pp_is_const = FALSE;
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
3568
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3569 // something->method()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3570 // Apply the '!', '-' and '+' first:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3571 // -1.0->func() works like (-1.0)->func()
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3572 if (compile_leader(cctx, TRUE, start_leader, end_leader) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3573 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3574
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
3575 p += 2;
20949
62912ad41aff patch 8.2.1026: Vim9: cannot break the line after "->"
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
3576 *arg = skipwhite(p);
21455
8cc1555f2445 patch 8.2.1278: Vim9: line break after "->" only allowed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21443
diff changeset
3577 // No line break supported right after "->".
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
3578 if (**arg == '(')
23318
c76240efdf02 patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents: 23310
diff changeset
3579 {
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3580 int argcount = 1;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3581 char_u *expr;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3582 garray_T *stack;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3583 type_T *type;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3584
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3585 // Funcref call: list->(Refs[2])(arg)
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3586 // or lambda: list->((arg) => expr)(arg)
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3587 // Fist compile the arguments.
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3588 expr = *arg;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3589 *arg = skipwhite(*arg + 1);
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3590 skip_expr_cctx(arg, cctx);
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3591 *arg = skipwhite(*arg);
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3592 if (**arg != ')')
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3593 {
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3594 semsg(_(e_missing_paren), *arg);
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3595 return FAIL;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3596 }
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3597 ++*arg;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3598 if (**arg != '(')
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3599 {
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
3600 if (*skipwhite(*arg) == '(')
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
3601 emsg(_(e_nowhitespace));
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
3602 else
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
3603 semsg(_(e_missing_paren), *arg);
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3604 return FAIL;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3605 }
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3606
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3607 *arg = skipwhite(*arg + 1);
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3608 if (compile_arguments(arg, cctx, &argcount) == FAIL)
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3609 return FAIL;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3610
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3611 // Compile the function expression.
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3612 if (compile_parenthesis(&expr, cctx, ppconst) == FAIL)
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3613 return FAIL;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3614
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3615 stack = &cctx->ctx_type_stack;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3616 type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3617 if (generate_PCALL(cctx, argcount,
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3618 (char_u *)"[expression]", type, FALSE) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3619 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3620 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3621 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3622 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3623 // method call: list->method()
19848
36d629aa3d6e patch 8.2.0480: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19830
diff changeset
3624 p = *arg;
21455
8cc1555f2445 patch 8.2.1278: Vim9: line break after "->" only allowed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21443
diff changeset
3625 if (!eval_isnamec1(*p))
8cc1555f2445 patch 8.2.1278: Vim9: line break after "->" only allowed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21443
diff changeset
3626 {
21465
b5d4ab124782 patch 8.2.1283: Vim9: error for misplaced -> lacks argument
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
3627 semsg(_(e_trailing_arg), pstart);
21455
8cc1555f2445 patch 8.2.1278: Vim9: line break after "->" only allowed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21443
diff changeset
3628 return FAIL;
8cc1555f2445 patch 8.2.1278: Vim9: line break after "->" only allowed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21443
diff changeset
3629 }
19848
36d629aa3d6e patch 8.2.0480: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19830
diff changeset
3630 if (ASCII_ISALPHA(*p) && p[1] == ':')
36d629aa3d6e patch 8.2.0480: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19830
diff changeset
3631 p += 2;
21650
79a8d723a3d2 patch 8.2.1375: Vim9: method name with digit not accepted
Bram Moolenaar <Bram@vim.org>
parents: 21648
diff changeset
3632 for ( ; eval_isnamec(*p); ++p)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3633 ;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3634 if (*p != '(')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3635 {
19848
36d629aa3d6e patch 8.2.0480: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19830
diff changeset
3636 semsg(_(e_missing_paren), *arg);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3637 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3638 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3639 // TODO: base value may not be the first argument
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3640 if (compile_call(arg, p - *arg, cctx, ppconst, 1) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3641 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3642 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3643 }
21562
55aa283a0e5e patch 8.2.1331: Vim9: :echo with two lists doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21558
diff changeset
3644 else if (**arg == '[')
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3645 {
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
3646 garray_T *stack = &cctx->ctx_type_stack;
19423
f3e8e74cb747 patch 8.2.0269: Vim9: operator after list index does not work
Bram Moolenaar <Bram@vim.org>
parents: 19411
diff changeset
3647 type_T **typep;
21831
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21828
diff changeset
3648 type_T *valtype;
21387
8d58cbb07a12 patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
3649 vartype_T vtype;
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3650 int is_slice = FALSE;
19423
f3e8e74cb747 patch 8.2.0269: Vim9: operator after list index does not work
Bram Moolenaar <Bram@vim.org>
parents: 19411
diff changeset
3651
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
3652 // list index: list[123]
20419
d54dfb5f12db patch 8.2.0764: Vim9: assigning to option not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20397
diff changeset
3653 // dict member: dict[key]
21393
320581a133d9 patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents: 21391
diff changeset
3654 // string index: text[123]
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
3655 // TODO: blob index
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
3656 // TODO: more arguments
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
3657 // TODO: recognize list or dict at runtime
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
3658 if (generate_ppconst(cctx, ppconst) == FAIL)
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
3659 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3660 ppconst->pp_is_const = FALSE;
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
3661
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
3662 ++p;
21248
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
3663 if (may_get_next_line_error(p, arg, cctx) == FAIL)
20949
62912ad41aff patch 8.2.1026: Vim9: cannot break the line after "->"
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
3664 return FAIL;
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3665 if (**arg == ':')
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
3666 {
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3667 // missing first index is equal to zero
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3668 generate_PUSHNR(cctx, 0);
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
3669 }
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3670 else
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3671 {
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3672 if (compile_expr0(arg, cctx) == FAIL)
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3673 return FAIL;
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
3674 if (**arg == ':')
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
3675 {
23446
b1dbbc81a011 patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Bram Moolenaar <Bram@vim.org>
parents: 23440
diff changeset
3676 semsg(_(e_white_space_required_before_and_after_str_at_str),
b1dbbc81a011 patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Bram Moolenaar <Bram@vim.org>
parents: 23440
diff changeset
3677 ":", *arg);
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
3678 return FAIL;
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
3679 }
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
3680 if (may_get_next_line_error(*arg, arg, cctx) == FAIL)
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3681 return FAIL;
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3682 *arg = skipwhite(*arg);
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3683 }
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3684 if (**arg == ':')
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3685 {
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
3686 is_slice = TRUE;
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
3687 ++*arg;
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
3688 if (!IS_WHITE_OR_NUL(**arg) && **arg != ']')
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
3689 {
23446
b1dbbc81a011 patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Bram Moolenaar <Bram@vim.org>
parents: 23440
diff changeset
3690 semsg(_(e_white_space_required_before_and_after_str_at_str),
b1dbbc81a011 patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Bram Moolenaar <Bram@vim.org>
parents: 23440
diff changeset
3691 ":", *arg);
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
3692 return FAIL;
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
3693 }
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
3694 if (may_get_next_line_error(*arg, arg, cctx) == FAIL)
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3695 return FAIL;
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3696 if (**arg == ']')
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3697 // missing second index is equal to end of string
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3698 generate_PUSHNR(cctx, -1);
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3699 else
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3700 {
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3701 if (compile_expr0(arg, cctx) == FAIL)
23106
b0c88aa0175b patch 8.2.2099: Vim9: some checks are not tested
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
3702 return FAIL;
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
3703 if (may_get_next_line_error(*arg, arg, cctx) == FAIL)
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3704 return FAIL;
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3705 *arg = skipwhite(*arg);
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3706 }
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3707 }
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3708
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3709 if (**arg != ']')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3710 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3711 emsg(_(e_missbrac));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3712 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3713 }
19342
8ff84bc1c89b patch 8.2.0229: compare instructions not tested
Bram Moolenaar <Bram@vim.org>
parents: 19336
diff changeset
3714 *arg = *arg + 1;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3715
21387
8d58cbb07a12 patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
3716 // We can index a list and a dict. If we don't know the type
8d58cbb07a12 patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
3717 // we can use the index value type.
8d58cbb07a12 patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
3718 // TODO: If we don't know use an instruction to figure it out at
8d58cbb07a12 patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
3719 // runtime.
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3720 typep = ((type_T **)stack->ga_data) + stack->ga_len
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3721 - (is_slice ? 3 : 2);
21387
8d58cbb07a12 patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
3722 vtype = (*typep)->tt_type;
21831
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21828
diff changeset
3723 valtype = ((type_T **)stack->ga_data)[stack->ga_len - 1];
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21828
diff changeset
3724 // If the index is a string, the variable must be a Dict.
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21828
diff changeset
3725 if (*typep == &t_any && valtype == &t_string)
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21828
diff changeset
3726 vtype = VAR_DICT;
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21828
diff changeset
3727 if (vtype == VAR_STRING || vtype == VAR_LIST || vtype == VAR_BLOB)
21387
8d58cbb07a12 patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
3728 {
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3729 if (need_type(valtype, &t_number, -1, cctx,
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3730 FALSE, FALSE) == FAIL)
21831
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21828
diff changeset
3731 return FAIL;
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21828
diff changeset
3732 if (is_slice)
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21828
diff changeset
3733 {
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21828
diff changeset
3734 valtype = ((type_T **)stack->ga_data)[stack->ga_len - 2];
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3735 if (need_type(valtype, &t_number, -2, cctx,
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3736 FALSE, FALSE) == FAIL)
21831
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21828
diff changeset
3737 return FAIL;
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21828
diff changeset
3738 }
21387
8d58cbb07a12 patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
3739 }
21831
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21828
diff changeset
3740
21387
8d58cbb07a12 patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
3741 if (vtype == VAR_DICT)
8d58cbb07a12 patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
3742 {
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3743 if (is_slice)
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3744 {
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3745 emsg(_(e_cannot_slice_dictionary));
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3746 return FAIL;
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3747 }
21387
8d58cbb07a12 patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
3748 if ((*typep)->tt_type == VAR_DICT)
8d58cbb07a12 patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
3749 *typep = (*typep)->tt_member;
21411
e1aeb986712f patch 8.2.1256: Vim9: type wrong after getting dict item in lambda
Bram Moolenaar <Bram@vim.org>
parents: 21399
diff changeset
3750 else
e1aeb986712f patch 8.2.1256: Vim9: type wrong after getting dict item in lambda
Bram Moolenaar <Bram@vim.org>
parents: 21399
diff changeset
3751 {
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3752 if (need_type(*typep, &t_dict_any, -2, cctx,
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3753 FALSE, FALSE) == FAIL)
21411
e1aeb986712f patch 8.2.1256: Vim9: type wrong after getting dict item in lambda
Bram Moolenaar <Bram@vim.org>
parents: 21399
diff changeset
3754 return FAIL;
e1aeb986712f patch 8.2.1256: Vim9: type wrong after getting dict item in lambda
Bram Moolenaar <Bram@vim.org>
parents: 21399
diff changeset
3755 *typep = &t_any;
e1aeb986712f patch 8.2.1256: Vim9: type wrong after getting dict item in lambda
Bram Moolenaar <Bram@vim.org>
parents: 21399
diff changeset
3756 }
21387
8d58cbb07a12 patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
3757 if (may_generate_2STRING(-1, cctx) == FAIL)
8d58cbb07a12 patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
3758 return FAIL;
8d58cbb07a12 patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
3759 if (generate_instr_drop(cctx, ISN_MEMBER, 1) == FAIL)
8d58cbb07a12 patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
3760 return FAIL;
8d58cbb07a12 patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
3761 }
21393
320581a133d9 patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents: 21391
diff changeset
3762 else if (vtype == VAR_STRING)
320581a133d9 patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents: 21391
diff changeset
3763 {
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3764 *typep = &t_string;
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3765 if ((is_slice
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3766 ? generate_instr_drop(cctx, ISN_STRSLICE, 2)
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3767 : generate_instr_drop(cctx, ISN_STRINDEX, 1)) == FAIL)
21393
320581a133d9 patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents: 21391
diff changeset
3768 return FAIL;
320581a133d9 patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents: 21391
diff changeset
3769 }
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3770 else if (vtype == VAR_BLOB)
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3771 {
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3772 emsg("Sorry, blob index and slice not implemented yet");
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3773 return FAIL;
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3774 }
21387
8d58cbb07a12 patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
3775 else if (vtype == VAR_LIST || *typep == &t_any)
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
3776 {
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3777 if (is_slice)
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3778 {
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3779 if (generate_instr_drop(cctx,
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3780 vtype == VAR_LIST ? ISN_LISTSLICE : ISN_ANYSLICE,
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3781 2) == FAIL)
21828
af5db9b6d210 patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21826
diff changeset
3782 return FAIL;
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
3783 }
21828
af5db9b6d210 patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21826
diff changeset
3784 else
af5db9b6d210 patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21826
diff changeset
3785 {
af5db9b6d210 patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21826
diff changeset
3786 if ((*typep)->tt_type == VAR_LIST)
af5db9b6d210 patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21826
diff changeset
3787 *typep = (*typep)->tt_member;
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3788 if (generate_instr_drop(cctx,
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3789 vtype == VAR_LIST ? ISN_LISTINDEX : ISN_ANYINDEX,
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3790 1) == FAIL)
21828
af5db9b6d210 patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21826
diff changeset
3791 return FAIL;
af5db9b6d210 patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21826
diff changeset
3792 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
3793 }
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
3794 else
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
3795 {
21831
d8422de73113 patch 8.2.1465: Vim9: subscript not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21828
diff changeset
3796 emsg(_(e_string_list_dict_or_blob_required));
19423
f3e8e74cb747 patch 8.2.0269: Vim9: operator after list index does not work
Bram Moolenaar <Bram@vim.org>
parents: 19411
diff changeset
3797 return FAIL;
f3e8e74cb747 patch 8.2.0269: Vim9: operator after list index does not work
Bram Moolenaar <Bram@vim.org>
parents: 19411
diff changeset
3798 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3799 }
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
3800 else if (*p == '.' && p[1] != '.')
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3801 {
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3802 // dictionary member: dict.name
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
3803 if (generate_ppconst(cctx, ppconst) == FAIL)
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
3804 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3805 ppconst->pp_is_const = FALSE;
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
3806
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
3807 *arg = p + 1;
20949
62912ad41aff patch 8.2.1026: Vim9: cannot break the line after "->"
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
3808 if (may_get_next_line(*arg, arg, cctx) == FAIL)
22482
a1b3804163ca patch 8.2.1789: Vim9: crash with invalid list constant
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
3809 {
a1b3804163ca patch 8.2.1789: Vim9: crash with invalid list constant
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
3810 emsg(_(e_missing_name_after_dot));
20949
62912ad41aff patch 8.2.1026: Vim9: cannot break the line after "->"
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
3811 return FAIL;
22482
a1b3804163ca patch 8.2.1789: Vim9: crash with invalid list constant
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
3812 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3813 p = *arg;
21512
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21504
diff changeset
3814 if (eval_isdictc(*p))
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3815 while (eval_isnamec(*p))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3816 MB_PTR_ADV(p);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3817 if (p == *arg)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3818 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
3819 semsg(_(e_syntax_error_at_str), *arg);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3820 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3821 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
3822 if (generate_STRINGMEMBER(cctx, *arg, p - *arg) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3823 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3824 *arg = p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3825 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3826 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3827 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3828 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3829
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3830 // TODO - see handle_subscript():
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3831 // Turn "dict.Func" into a partial for "Func" bound to "dict".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3832 // Don't do this when "Func" is already a partial that was bound
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3833 // explicitly (pt_auto is FALSE).
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3834
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3835 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3836 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3837
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3838 /*
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
3839 * Compile an expression at "*arg" and add instructions to "cctx->ctx_instr".
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
3840 * "arg" is advanced until after the expression, skipping white space.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3841 *
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3842 * If the value is a constant "ppconst->pp_used" will be non-zero.
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
3843 * Before instructions are generated, any values in "ppconst" will generated.
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
3844 *
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
3845 * This is the compiling equivalent of eval1(), eval2(), etc.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3846 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3847
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3848 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3849 * number number constant
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3850 * 0zFFFFFFFF Blob constant
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3851 * "string" string constant
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3852 * 'string' literal string constant
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3853 * &option-name option value
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3854 * @r register contents
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3855 * identifier variable value
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3856 * function() function call
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3857 * $VAR environment variable
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3858 * (expression) nested expression
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3859 * [expr, expr] List
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
3860 * {key: val, [key]: val} Dictionary
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3861 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3862 * Also handle:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3863 * ! in front logical NOT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3864 * - in front unary minus
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3865 * + in front unary plus (ignored)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3866 * trailing (arg) funcref/partial call
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3867 * trailing [] subscript in String or List
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3868 * trailing .name entry in Dictionary
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3869 * trailing ->name() method call
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3870 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3871 static int
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
3872 compile_expr7(
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
3873 char_u **arg,
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
3874 cctx_T *cctx,
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
3875 ppconst_T *ppconst)
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
3876 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3877 char_u *start_leader, *end_leader;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3878 int ret = OK;
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
3879 typval_T *rettv = &ppconst->pp_tv[ppconst->pp_used];
20336
2fd980fb9ab3 patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents: 20334
diff changeset
3880 int used_before = ppconst->pp_used;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3881
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3882 ppconst->pp_is_const = FALSE;
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3883
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3884 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3885 * Skip '!', '-' and '+' characters. They are handled later.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3886 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3887 start_leader = *arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3888 while (**arg == '!' || **arg == '-' || **arg == '+')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3889 *arg = skipwhite(*arg + 1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3890 end_leader = *arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3891
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
3892 rettv->v_type = VAR_UNKNOWN;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3893 switch (**arg)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3894 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3895 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3896 * Number constant.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3897 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3898 case '0': // also for blob starting with 0z
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3899 case '1':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3900 case '2':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3901 case '3':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3902 case '4':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3903 case '5':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3904 case '6':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3905 case '7':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3906 case '8':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3907 case '9':
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21116
diff changeset
3908 case '.': if (eval_number(arg, rettv, TRUE, FALSE) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3909 return FAIL;
21743
a7e0091a4669 patch 8.2.1421: Vim9: handling "+" and "-" before number differs from script
Bram Moolenaar <Bram@vim.org>
parents: 21739
diff changeset
3910 // Apply "-" and "+" just before the number now, right to
a7e0091a4669 patch 8.2.1421: Vim9: handling "+" and "-" before number differs from script
Bram Moolenaar <Bram@vim.org>
parents: 21739
diff changeset
3911 // left. Matters especially when "->" follows. Stops at
a7e0091a4669 patch 8.2.1421: Vim9: handling "+" and "-" before number differs from script
Bram Moolenaar <Bram@vim.org>
parents: 21739
diff changeset
3912 // '!'.
a7e0091a4669 patch 8.2.1421: Vim9: handling "+" and "-" before number differs from script
Bram Moolenaar <Bram@vim.org>
parents: 21739
diff changeset
3913 if (apply_leader(rettv, TRUE,
a7e0091a4669 patch 8.2.1421: Vim9: handling "+" and "-" before number differs from script
Bram Moolenaar <Bram@vim.org>
parents: 21739
diff changeset
3914 start_leader, &end_leader) == FAIL)
a7e0091a4669 patch 8.2.1421: Vim9: handling "+" and "-" before number differs from script
Bram Moolenaar <Bram@vim.org>
parents: 21739
diff changeset
3915 {
a7e0091a4669 patch 8.2.1421: Vim9: handling "+" and "-" before number differs from script
Bram Moolenaar <Bram@vim.org>
parents: 21739
diff changeset
3916 clear_tv(rettv);
a7e0091a4669 patch 8.2.1421: Vim9: handling "+" and "-" before number differs from script
Bram Moolenaar <Bram@vim.org>
parents: 21739
diff changeset
3917 return FAIL;
a7e0091a4669 patch 8.2.1421: Vim9: handling "+" and "-" before number differs from script
Bram Moolenaar <Bram@vim.org>
parents: 21739
diff changeset
3918 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3919 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3920
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3921 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3922 * String constant: "string".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3923 */
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21116
diff changeset
3924 case '"': if (eval_string(arg, rettv, TRUE) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3925 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3926 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3927
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3928 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3929 * Literal string constant: 'str''ing'.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3930 */
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21116
diff changeset
3931 case '\'': if (eval_lit_string(arg, rettv, TRUE) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3932 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3933 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3934
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3935 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3936 * Constant Vim variable.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3937 */
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
3938 case 'v': get_vim_constant(arg, rettv);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3939 ret = NOTDONE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3940 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3941
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3942 /*
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3943 * "true" constant
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3944 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3945 case 't': if (STRNCMP(*arg, "true", 4) == 0
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3946 && !eval_isnamec((*arg)[4]))
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3947 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3948 *arg += 4;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3949 rettv->v_type = VAR_BOOL;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3950 rettv->vval.v_number = VVAL_TRUE;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3951 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3952 else
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3953 ret = NOTDONE;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3954 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3955
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3956 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3957 * "false" constant
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3958 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3959 case 'f': if (STRNCMP(*arg, "false", 5) == 0
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3960 && !eval_isnamec((*arg)[5]))
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3961 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3962 *arg += 5;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3963 rettv->v_type = VAR_BOOL;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3964 rettv->vval.v_number = VVAL_FALSE;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3965 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3966 else
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3967 ret = NOTDONE;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3968 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3969
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3970 /*
23497
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
3971 * "null" constant
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
3972 */
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
3973 case 'n': if (STRNCMP(*arg, "null", 4) == 0
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
3974 && !eval_isnamec((*arg)[5]))
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
3975 {
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
3976 *arg += 4;
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
3977 rettv->v_type = VAR_SPECIAL;
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
3978 rettv->vval.v_number = VVAL_NULL;
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
3979 }
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
3980 else
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
3981 ret = NOTDONE;
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
3982 break;
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
3983
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
3984 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3985 * List: [expr, expr]
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3986 */
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3987 case '[': ret = compile_list(arg, cctx, ppconst);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3988 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3989
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3990 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3991 * Dictionary: {'key': val, 'key': val}
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3992 */
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
3993 case '{': ret = compile_dict(arg, cctx, ppconst);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3994 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3995
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3996 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3997 * Option value: &name
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3998 */
21903
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
3999 case '&': if (generate_ppconst(cctx, ppconst) == FAIL)
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4000 return FAIL;
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4001 ret = compile_get_option(arg, cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4002 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4003
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4004 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4005 * Environment variable: $VAR.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4006 */
21903
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4007 case '$': if (generate_ppconst(cctx, ppconst) == FAIL)
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4008 return FAIL;
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4009 ret = compile_get_env(arg, cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4010 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4011
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4012 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4013 * Register contents: @r.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4014 */
21903
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4015 case '@': if (generate_ppconst(cctx, ppconst) == FAIL)
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4016 return FAIL;
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4017 ret = compile_get_register(arg, cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4018 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4019 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4020 * nested expression: (expression).
23318
c76240efdf02 patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents: 23310
diff changeset
4021 * lambda: (arg, arg) => expr
c76240efdf02 patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents: 23310
diff changeset
4022 * funcref: (arg, arg) => { statement }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4023 */
23368
a7cbdb9294c4 patch 8.2.2227: Vim9: recognizing lambda is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 23364
diff changeset
4024 case '(': // if compile_lambda returns NOTDONE then it must be (expr)
a7cbdb9294c4 patch 8.2.2227: Vim9: recognizing lambda is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 23364
diff changeset
4025 ret = compile_lambda(arg, cctx);
a7cbdb9294c4 patch 8.2.2227: Vim9: recognizing lambda is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 23364
diff changeset
4026 if (ret == NOTDONE)
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4027 ret = compile_parenthesis(arg, cctx, ppconst);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4028 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4029
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4030 default: ret = NOTDONE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4031 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4032 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4033 if (ret == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4034 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4035
20336
2fd980fb9ab3 patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents: 20334
diff changeset
4036 if (rettv->v_type != VAR_UNKNOWN && used_before == ppconst->pp_used)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4037 {
20907
4eeda7139133 patch 8.2.1005: Vim9: using TRUE/FALSE/MAYBE for ctx_skip is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20899
diff changeset
4038 if (cctx->ctx_skip == SKIP_YES)
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4039 clear_tv(rettv);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4040 else
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4041 // A constant expression can possibly be handled compile time,
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4042 // return the value instead of generating code.
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4043 ++ppconst->pp_used;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4044 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4045 else if (ret == NOTDONE)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4046 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4047 char_u *p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4048 int r;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4049
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4050 if (!eval_isnamec1(**arg))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4051 {
23183
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
4052 if (ends_excmd(*skipwhite(*arg)))
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
4053 semsg(_(e_empty_expression_str), *arg);
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
4054 else
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
4055 semsg(_(e_name_expected_str), *arg);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4056 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4057 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4058
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4059 // "name" or "name()"
19583
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
4060 p = to_name_end(*arg, TRUE);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4061 if (*p == '(')
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4062 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4063 r = compile_call(arg, p - *arg, cctx, ppconst, 0);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4064 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4065 else
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4066 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4067 if (generate_ppconst(cctx, ppconst) == FAIL)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4068 return FAIL;
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
4069 r = compile_load(arg, p, cctx, TRUE, TRUE);
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4070 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4071 if (r == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4072 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4073 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4074
20322
a3e78893a90b patch 8.2.0716: Vim9: another memory leak
Bram Moolenaar <Bram@vim.org>
parents: 20320
diff changeset
4075 // Handle following "[]", ".member", etc.
a3e78893a90b patch 8.2.0716: Vim9: another memory leak
Bram Moolenaar <Bram@vim.org>
parents: 20320
diff changeset
4076 // Then deal with prefixed '-', '+' and '!', if not done already.
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4077 if (compile_subscript(arg, cctx, start_leader, &end_leader,
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4078 ppconst) == FAIL)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4079 return FAIL;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4080 if (ppconst->pp_used > 0)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4081 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4082 // apply the '!', '-' and '+' before the constant
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4083 rettv = &ppconst->pp_tv[ppconst->pp_used - 1];
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4084 if (apply_leader(rettv, FALSE, start_leader, &end_leader) == FAIL)
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4085 return FAIL;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4086 return OK;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4087 }
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4088 if (compile_leader(cctx, FALSE, start_leader, &end_leader) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4089 return FAIL;
20322
a3e78893a90b patch 8.2.0716: Vim9: another memory leak
Bram Moolenaar <Bram@vim.org>
parents: 20320
diff changeset
4090 return OK;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4091 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4092
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4093 /*
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4094 * Give the "white on both sides" error, taking the operator from "p[len]".
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4095 */
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4096 void
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4097 error_white_both(char_u *op, int len)
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4098 {
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4099 char_u buf[10];
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4100
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4101 vim_strncpy(buf, op, len);
23446
b1dbbc81a011 patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Bram Moolenaar <Bram@vim.org>
parents: 23440
diff changeset
4102 semsg(_(e_white_space_required_before_and_after_str_at_str), buf, op);
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4103 }
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4104
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4105 /*
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4106 * <type>expr7: runtime type check / conversion
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4107 */
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4108 static int
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4109 compile_expr7t(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4110 {
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4111 type_T *want_type = NULL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4112
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4113 // Recognize <type>
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4114 if (**arg == '<' && eval_isnamec1((*arg)[1]))
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4115 {
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4116 ++*arg;
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
4117 want_type = parse_type(arg, cctx->ctx_type_list, TRUE);
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
4118 if (want_type == NULL)
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4119 return FAIL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4120
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4121 if (**arg != '>')
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4122 {
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4123 if (*skipwhite(*arg) == '>')
21909
a211bca98bc3 patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents: 21903
diff changeset
4124 semsg(_(e_no_white_space_allowed_before_str), ">");
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4125 else
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
4126 emsg(_(e_missing_gt));
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4127 return FAIL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4128 }
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4129 ++*arg;
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
4130 if (may_get_next_line_error(*arg, arg, cctx) == FAIL)
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4131 return FAIL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4132 }
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4133
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4134 if (compile_expr7(arg, cctx, ppconst) == FAIL)
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4135 return FAIL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4136
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4137 if (want_type != NULL)
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4138 {
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4139 garray_T *stack = &cctx->ctx_type_stack;
21811
3261e28c638a patch 8.2.1455: Vim9: crash when using typecast before constant
Bram Moolenaar <Bram@vim.org>
parents: 21809
diff changeset
4140 type_T *actual;
3261e28c638a patch 8.2.1455: Vim9: crash when using typecast before constant
Bram Moolenaar <Bram@vim.org>
parents: 21809
diff changeset
4141
3261e28c638a patch 8.2.1455: Vim9: crash when using typecast before constant
Bram Moolenaar <Bram@vim.org>
parents: 21809
diff changeset
4142 generate_ppconst(cctx, ppconst);
3261e28c638a patch 8.2.1455: Vim9: crash when using typecast before constant
Bram Moolenaar <Bram@vim.org>
parents: 21809
diff changeset
4143 actual = ((type_T **)stack->ga_data)[stack->ga_len - 1];
22004
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
4144 if (check_type(want_type, actual, FALSE, 0) == FAIL)
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4145 {
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4146 if (need_type(actual, want_type, -1, cctx, FALSE, FALSE) == FAIL)
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4147 return FAIL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4148 }
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4149 }
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4150
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4151 return OK;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4152 }
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4153
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4154 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4155 * * number multiplication
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4156 * / number division
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4157 * % number modulo
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4158 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4159 static int
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4160 compile_expr6(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4161 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4162 char_u *op;
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4163 char_u *next;
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4164 int ppconst_used = ppconst->pp_used;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4165
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4166 // get the first expression
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4167 if (compile_expr7t(arg, cctx, ppconst) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4168 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4169
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4170 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4171 * Repeat computing, until no "*", "/" or "%" is following.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4172 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4173 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4174 {
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4175 op = may_peek_next_line(cctx, *arg, &next);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4176 if (*op != '*' && *op != '/' && *op != '%')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4177 break;
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4178 if (next != NULL)
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4179 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4180 *arg = next_line_from_context(cctx, TRUE);
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4181 op = skipwhite(*arg);
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4182 }
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4183
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4184 if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(op[1]))
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4185 {
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4186 error_white_both(op, 1);
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4187 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4188 }
23106
b0c88aa0175b patch 8.2.2099: Vim9: some checks are not tested
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
4189 if (may_get_next_line_error(op + 1, arg, cctx) == FAIL)
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4190 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4191
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4192 // get the second expression
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4193 if (compile_expr7t(arg, cctx, ppconst) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4194 return FAIL;
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4195
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4196 if (ppconst->pp_used == ppconst_used + 2
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4197 && ppconst->pp_tv[ppconst_used].v_type == VAR_NUMBER
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4198 && ppconst->pp_tv[ppconst_used + 1].v_type == VAR_NUMBER)
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4199 {
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4200 typval_T *tv1 = &ppconst->pp_tv[ppconst_used];
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4201 typval_T *tv2 = &ppconst->pp_tv[ppconst_used + 1];
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4202 varnumber_T res = 0;
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4203
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4204 // both are numbers: compute the result
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4205 switch (*op)
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4206 {
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4207 case '*': res = tv1->vval.v_number * tv2->vval.v_number;
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4208 break;
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4209 case '/': res = tv1->vval.v_number / tv2->vval.v_number;
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4210 break;
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4211 case '%': res = tv1->vval.v_number % tv2->vval.v_number;
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4212 break;
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4213 }
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4214 tv1->vval.v_number = res;
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4215 --ppconst->pp_used;
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4216 }
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4217 else
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4218 {
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4219 generate_ppconst(cctx, ppconst);
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4220 generate_two_op(cctx, op);
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4221 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4222 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4223
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4224 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4225 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4226
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4227 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4228 * + number addition
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4229 * - number subtraction
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4230 * .. string concatenation
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4231 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4232 static int
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4233 compile_expr5(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4234 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4235 char_u *op;
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4236 char_u *next;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4237 int oplen;
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4238 int ppconst_used = ppconst->pp_used;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4239
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4240 // get the first variable
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4241 if (compile_expr6(arg, cctx, ppconst) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4242 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4243
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4244 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4245 * Repeat computing, until no "+", "-" or ".." is following.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4246 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4247 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4248 {
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4249 op = may_peek_next_line(cctx, *arg, &next);
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4250 if (*op != '+' && *op != '-' && !(*op == '.' && *(op + 1) == '.'))
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4251 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4252 oplen = (*op == '.' ? 2 : 1);
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4253 if (next != NULL)
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4254 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4255 *arg = next_line_from_context(cctx, TRUE);
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4256 op = skipwhite(*arg);
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4257 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4258
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4259 if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(op[oplen]))
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4260 {
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4261 error_white_both(op, oplen);
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4262 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4263 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4264
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
4265 if (may_get_next_line_error(op + oplen, arg, cctx) == FAIL)
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4266 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4267
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4268 // get the second expression
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4269 if (compile_expr6(arg, cctx, ppconst) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4270 return FAIL;
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4271
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4272 if (ppconst->pp_used == ppconst_used + 2
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4273 && (*op == '.'
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4274 ? (ppconst->pp_tv[ppconst_used].v_type == VAR_STRING
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4275 && ppconst->pp_tv[ppconst_used + 1].v_type == VAR_STRING)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4276 : (ppconst->pp_tv[ppconst_used].v_type == VAR_NUMBER
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4277 && ppconst->pp_tv[ppconst_used + 1].v_type == VAR_NUMBER)))
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4278 {
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4279 typval_T *tv1 = &ppconst->pp_tv[ppconst_used];
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4280 typval_T *tv2 = &ppconst->pp_tv[ppconst_used + 1];
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4281
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4282 // concat/subtract/add constant numbers
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4283 if (*op == '+')
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4284 tv1->vval.v_number = tv1->vval.v_number + tv2->vval.v_number;
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4285 else if (*op == '-')
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4286 tv1->vval.v_number = tv1->vval.v_number - tv2->vval.v_number;
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4287 else
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4288 {
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4289 // concatenate constant strings
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4290 char_u *s1 = tv1->vval.v_string;
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4291 char_u *s2 = tv2->vval.v_string;
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4292 size_t len1 = STRLEN(s1);
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4293
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4294 tv1->vval.v_string = alloc((int)(len1 + STRLEN(s2) + 1));
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4295 if (tv1->vval.v_string == NULL)
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4296 {
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4297 clear_ppconst(ppconst);
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4298 return FAIL;
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4299 }
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4300 mch_memmove(tv1->vval.v_string, s1, len1);
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4301 STRCPY(tv1->vval.v_string + len1, s2);
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4302 vim_free(s1);
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4303 vim_free(s2);
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4304 }
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4305 --ppconst->pp_used;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4306 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4307 else
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4308 {
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4309 generate_ppconst(cctx, ppconst);
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4310 if (*op == '.')
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4311 {
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4312 if (may_generate_2STRING(-2, cctx) == FAIL
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4313 || may_generate_2STRING(-1, cctx) == FAIL)
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4314 return FAIL;
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4315 generate_instr_drop(cctx, ISN_CONCAT, 1);
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4316 }
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4317 else
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4318 generate_two_op(cctx, op);
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4319 }
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4320 }
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4321
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4322 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4323 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4324
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4325 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4326 * expr5a == expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4327 * expr5a =~ expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4328 * expr5a != expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4329 * expr5a !~ expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4330 * expr5a > expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4331 * expr5a >= expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4332 * expr5a < expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4333 * expr5a <= expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4334 * expr5a is expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4335 * expr5a isnot expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4336 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4337 * Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4338 * EVAL expr5a Push result of "expr5a"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4339 * EVAL expr5b Push result of "expr5b"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4340 * COMPARE one of the compare instructions
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4341 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4342 static int
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4343 compile_expr4(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4344 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4345 exptype_T type = EXPR_UNKNOWN;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4346 char_u *p;
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4347 char_u *next;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4348 int len = 2;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4349 int type_is = FALSE;
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4350 int ppconst_used = ppconst->pp_used;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4351
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4352 // get the first variable
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4353 if (compile_expr5(arg, cctx, ppconst) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4354 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4355
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4356 p = may_peek_next_line(cctx, *arg, &next);
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
4357 type = get_compare_type(p, &len, &type_is);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4358
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4359 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4360 * If there is a comparative operator, use it.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4361 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4362 if (type != EXPR_UNKNOWN)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4363 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4364 int ic = FALSE; // Default: do not ignore case
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4365
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4366 if (next != NULL)
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4367 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4368 *arg = next_line_from_context(cctx, TRUE);
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4369 p = skipwhite(*arg);
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4370 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4371 if (type_is && (p[len] == '?' || p[len] == '#'))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4372 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4373 semsg(_(e_invexpr2), *arg);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4374 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4375 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4376 // extra question mark appended: ignore case
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4377 if (p[len] == '?')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4378 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4379 ic = TRUE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4380 ++len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4381 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4382 // extra '#' appended: match case (ignored)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4383 else if (p[len] == '#')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4384 ++len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4385 // nothing appended: match case
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4386
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4387 if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[len]))
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4388 {
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4389 error_white_both(p, len);
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4390 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4391 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4392
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4393 // get the second variable
23106
b0c88aa0175b patch 8.2.2099: Vim9: some checks are not tested
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
4394 if (may_get_next_line_error(p + len, arg, cctx) == FAIL)
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4395 return FAIL;
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4396
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4397 if (compile_expr5(arg, cctx, ppconst) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4398 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4399
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4400 if (ppconst->pp_used == ppconst_used + 2)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4401 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4402 typval_T * tv1 = &ppconst->pp_tv[ppconst->pp_used - 2];
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4403 typval_T *tv2 = &ppconst->pp_tv[ppconst->pp_used - 1];
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4404 int ret;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4405
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4406 // Both sides are a constant, compute the result now.
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4407 // First check for a valid combination of types, this is more
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4408 // strict than typval_compare().
21251
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
4409 if (check_compare_types(type, tv1, tv2) == FAIL)
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4410 ret = FAIL;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4411 else
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4412 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4413 ret = typval_compare(tv1, tv2, type, ic);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4414 tv1->v_type = VAR_BOOL;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4415 tv1->vval.v_number = tv1->vval.v_number
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4416 ? VVAL_TRUE : VVAL_FALSE;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4417 clear_tv(tv2);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4418 --ppconst->pp_used;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4419 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4420 return ret;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4421 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4422
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4423 generate_ppconst(cctx, ppconst);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4424 return generate_COMPARE(cctx, type, ic);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4425 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4426
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4427 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4428 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4429
20334
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
4430 static int compile_expr3(char_u **arg, cctx_T *cctx, ppconst_T *ppconst);
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
4431
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4432 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4433 * Compile || or &&.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4434 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4435 static int
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4436 compile_and_or(
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4437 char_u **arg,
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4438 cctx_T *cctx,
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4439 char *op,
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4440 ppconst_T *ppconst,
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4441 int ppconst_used UNUSED)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4442 {
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4443 char_u *next;
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4444 char_u *p = may_peek_next_line(cctx, *arg, &next);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4445 int opchar = *op;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4446
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4447 if (p[0] == opchar && p[1] == opchar)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4448 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4449 garray_T *instr = &cctx->ctx_instr;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4450 garray_T end_ga;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4451
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4452 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4453 * Repeat until there is no following "||" or "&&"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4454 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4455 ga_init2(&end_ga, sizeof(int), 10);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4456 while (p[0] == opchar && p[1] == opchar)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4457 {
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4458 if (next != NULL)
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4459 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4460 *arg = next_line_from_context(cctx, TRUE);
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4461 p = skipwhite(*arg);
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4462 }
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4463
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4464 if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[2]))
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4465 {
23446
b1dbbc81a011 patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Bram Moolenaar <Bram@vim.org>
parents: 23440
diff changeset
4466 semsg(_(e_white_space_required_before_and_after_str_at_str),
b1dbbc81a011 patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Bram Moolenaar <Bram@vim.org>
parents: 23440
diff changeset
4467 op, *arg);
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4468 return FAIL;
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4469 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4470
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
4471 // TODO: use ppconst if the value is a constant and check
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
4472 // evaluating to bool
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4473 generate_ppconst(cctx, ppconst);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4474
22860
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
4475 // Every part must evaluate to a bool.
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
4476 if (bool_on_stack(cctx) == FAIL)
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
4477 {
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
4478 ga_clear(&end_ga);
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
4479 return FAIL;
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
4480 }
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
4481
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4482 if (ga_grow(&end_ga, 1) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4483 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4484 ga_clear(&end_ga);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4485 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4486 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4487 *(((int *)end_ga.ga_data) + end_ga.ga_len) = instr->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4488 ++end_ga.ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4489 generate_JUMP(cctx, opchar == '|'
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
4490 ? JUMP_IF_COND_TRUE : JUMP_IF_COND_FALSE, 0);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4491
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4492 // eval the next expression
23106
b0c88aa0175b patch 8.2.2099: Vim9: some checks are not tested
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
4493 if (may_get_next_line_error(p + 2, arg, cctx) == FAIL)
23110
545ff3b4543c patch 8.2.2101: Vim9: memory leak when literal dict has an error
Bram Moolenaar <Bram@vim.org>
parents: 23106
diff changeset
4494 {
545ff3b4543c patch 8.2.2101: Vim9: memory leak when literal dict has an error
Bram Moolenaar <Bram@vim.org>
parents: 23106
diff changeset
4495 ga_clear(&end_ga);
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4496 return FAIL;
23110
545ff3b4543c patch 8.2.2101: Vim9: memory leak when literal dict has an error
Bram Moolenaar <Bram@vim.org>
parents: 23106
diff changeset
4497 }
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4498
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4499 if ((opchar == '|' ? compile_expr3(arg, cctx, ppconst)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4500 : compile_expr4(arg, cctx, ppconst)) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4501 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4502 ga_clear(&end_ga);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4503 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4504 }
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4505
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4506 p = may_peek_next_line(cctx, *arg, &next);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4507 }
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4508 generate_ppconst(cctx, ppconst);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4509
22860
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
4510 // Every part must evaluate to a bool.
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
4511 if (bool_on_stack(cctx) == FAIL)
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
4512 {
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
4513 ga_clear(&end_ga);
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
4514 return FAIL;
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
4515 }
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
4516
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4517 // Fill in the end label in all jumps.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4518 while (end_ga.ga_len > 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4519 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4520 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4521
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4522 --end_ga.ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4523 isn = ((isn_T *)instr->ga_data)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4524 + *(((int *)end_ga.ga_data) + end_ga.ga_len);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4525 isn->isn_arg.jump.jump_where = instr->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4526 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4527 ga_clear(&end_ga);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4528 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4529
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4530 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4531 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4532
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4533 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4534 * expr4a && expr4a && expr4a logical AND
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4535 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4536 * Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4537 * EVAL expr4a Push result of "expr4a"
22860
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
4538 * COND2BOOL convert to bool if needed
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
4539 * JUMP_IF_COND_FALSE end
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4540 * EVAL expr4b Push result of "expr4b"
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
4541 * JUMP_IF_COND_FALSE end
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4542 * EVAL expr4c Push result of "expr4c"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4543 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4544 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4545 static int
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4546 compile_expr3(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4547 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4548 int ppconst_used = ppconst->pp_used;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4549
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4550 // get the first variable
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4551 if (compile_expr4(arg, cctx, ppconst) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4552 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4553
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4554 // || and && work almost the same
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4555 return compile_and_or(arg, cctx, "&&", ppconst, ppconst_used);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4556 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4557
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4558 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4559 * expr3a || expr3b || expr3c logical OR
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4560 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4561 * Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4562 * EVAL expr3a Push result of "expr3a"
22860
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
4563 * COND2BOOL convert to bool if needed
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
4564 * JUMP_IF_COND_TRUE end
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4565 * EVAL expr3b Push result of "expr3b"
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
4566 * JUMP_IF_COND_TRUE end
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4567 * EVAL expr3c Push result of "expr3c"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4568 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4569 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4570 static int
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4571 compile_expr2(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4572 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4573 int ppconst_used = ppconst->pp_used;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4574
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4575 // eval the first expression
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4576 if (compile_expr3(arg, cctx, ppconst) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4577 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4578
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4579 // || and && work almost the same
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4580 return compile_and_or(arg, cctx, "||", ppconst, ppconst_used);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4581 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4582
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4583 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4584 * Toplevel expression: expr2 ? expr1a : expr1b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4585 * Produces instructions:
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4586 * EVAL expr2 Push result of "expr2"
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4587 * JUMP_IF_FALSE alt jump if false
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4588 * EVAL expr1a
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4589 * JUMP_ALWAYS end
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4590 * alt: EVAL expr1b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4591 * end:
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4592 *
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4593 * Toplevel expression: expr2 ?? expr1
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4594 * Produces instructions:
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4595 * EVAL expr2 Push result of "expr2"
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4596 * JUMP_AND_KEEP_IF_TRUE end jump if true
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4597 * EVAL expr1
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4598 * end:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4599 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4600 static int
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4601 compile_expr1(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4602 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4603 char_u *p;
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4604 int ppconst_used = ppconst->pp_used;
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4605 char_u *next;
20305
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4606
21957
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
4607 // Ignore all kinds of errors when not producing code.
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
4608 if (cctx->ctx_skip == SKIP_YES)
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
4609 {
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4610 skip_expr_cctx(arg, cctx);
21957
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
4611 return OK;
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
4612 }
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
4613
20305
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4614 // Evaluate the first expression.
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4615 if (compile_expr2(arg, cctx, ppconst) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4616 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4617
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4618 p = may_peek_next_line(cctx, *arg, &next);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4619 if (*p == '?')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4620 {
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4621 int op_falsy = p[1] == '?';
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4622 garray_T *instr = &cctx->ctx_instr;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4623 garray_T *stack = &cctx->ctx_type_stack;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4624 int alt_idx = instr->ga_len;
20966
0ee7de260208 patch 8.2.1034: compiler warning for uninitialized variables
Bram Moolenaar <Bram@vim.org>
parents: 20961
diff changeset
4625 int end_idx = 0;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4626 isn_T *isn;
20966
0ee7de260208 patch 8.2.1034: compiler warning for uninitialized variables
Bram Moolenaar <Bram@vim.org>
parents: 20961
diff changeset
4627 type_T *type1 = NULL;
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4628 int has_const_expr = FALSE;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4629 int const_value = FALSE;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4630 int save_skip = cctx->ctx_skip;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4631
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4632 if (next != NULL)
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4633 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4634 *arg = next_line_from_context(cctx, TRUE);
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4635 p = skipwhite(*arg);
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4636 }
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4637
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4638 if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[1 + op_falsy]))
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4639 {
23446
b1dbbc81a011 patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Bram Moolenaar <Bram@vim.org>
parents: 23440
diff changeset
4640 semsg(_(e_white_space_required_before_and_after_str_at_str),
b1dbbc81a011 patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Bram Moolenaar <Bram@vim.org>
parents: 23440
diff changeset
4641 op_falsy ? "??" : "?", *arg);
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4642 return FAIL;
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4643 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4644
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4645 if (ppconst->pp_used == ppconst_used + 1)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4646 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4647 // the condition is a constant, we know whether the ? or the :
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4648 // expression is to be evaluated.
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4649 has_const_expr = TRUE;
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
4650 if (op_falsy)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
4651 const_value = tv2bool(&ppconst->pp_tv[ppconst_used]);
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
4652 else
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
4653 {
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
4654 int error = FALSE;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
4655
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
4656 const_value = tv_get_bool_chk(&ppconst->pp_tv[ppconst_used],
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
4657 &error);
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
4658 if (error)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
4659 return FAIL;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
4660 }
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4661 cctx->ctx_skip = save_skip == SKIP_YES ||
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4662 (op_falsy ? const_value : !const_value) ? SKIP_YES : SKIP_NOT;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4663
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4664 if (op_falsy && cctx->ctx_skip == SKIP_YES)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4665 // "left ?? right" and "left" is truthy: produce "left"
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4666 generate_ppconst(cctx, ppconst);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4667 else
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4668 {
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4669 clear_tv(&ppconst->pp_tv[ppconst_used]);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4670 --ppconst->pp_used;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4671 }
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4672 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4673 else
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4674 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4675 generate_ppconst(cctx, ppconst);
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4676 if (op_falsy)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4677 end_idx = instr->ga_len;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4678 generate_JUMP(cctx, op_falsy
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4679 ? JUMP_AND_KEEP_IF_TRUE : JUMP_IF_FALSE, 0);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4680 if (op_falsy)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4681 type1 = ((type_T **)stack->ga_data)[stack->ga_len];
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4682 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4683
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4684 // evaluate the second expression; any type is accepted
23106
b0c88aa0175b patch 8.2.2099: Vim9: some checks are not tested
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
4685 if (may_get_next_line_error(p + 1 + op_falsy, arg, cctx) == FAIL)
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4686 return FAIL;
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4687 if (compile_expr1(arg, cctx, ppconst) == FAIL)
19223
173b99509038 patch 8.2.0170: Coverity warning for ignoring return value
Bram Moolenaar <Bram@vim.org>
parents: 19213
diff changeset
4688 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4689
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4690 if (!has_const_expr)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4691 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4692 generate_ppconst(cctx, ppconst);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4693
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4694 if (!op_falsy)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4695 {
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4696 // remember the type and drop it
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4697 --stack->ga_len;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4698 type1 = ((type_T **)stack->ga_data)[stack->ga_len];
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4699
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4700 end_idx = instr->ga_len;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4701 generate_JUMP(cctx, JUMP_ALWAYS, 0);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4702
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4703 // jump here from JUMP_IF_FALSE
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4704 isn = ((isn_T *)instr->ga_data) + alt_idx;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4705 isn->isn_arg.jump.jump_where = instr->ga_len;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4706 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4707 }
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4708
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4709 if (!op_falsy)
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4710 {
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4711 // Check for the ":".
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4712 p = may_peek_next_line(cctx, *arg, &next);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4713 if (*p != ':')
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4714 {
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4715 emsg(_(e_missing_colon));
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4716 return FAIL;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4717 }
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4718 if (next != NULL)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4719 {
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4720 *arg = next_line_from_context(cctx, TRUE);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4721 p = skipwhite(*arg);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4722 }
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4723
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4724 if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[1]))
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4725 {
23446
b1dbbc81a011 patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Bram Moolenaar <Bram@vim.org>
parents: 23440
diff changeset
4726 semsg(_(e_white_space_required_before_and_after_str_at_str),
b1dbbc81a011 patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Bram Moolenaar <Bram@vim.org>
parents: 23440
diff changeset
4727 ":", p);
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4728 return FAIL;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4729 }
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4730
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4731 // evaluate the third expression
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4732 if (has_const_expr)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4733 cctx->ctx_skip = save_skip == SKIP_YES || const_value
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4734 ? SKIP_YES : SKIP_NOT;
23106
b0c88aa0175b patch 8.2.2099: Vim9: some checks are not tested
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
4735 if (may_get_next_line_error(p + 1, arg, cctx) == FAIL)
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4736 return FAIL;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4737 if (compile_expr1(arg, cctx, ppconst) == FAIL)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4738 return FAIL;
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4739 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4740
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4741 if (!has_const_expr)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4742 {
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4743 type_T **typep;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4744
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4745 generate_ppconst(cctx, ppconst);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4746
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4747 // If the types differ, the result has a more generic type.
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4748 typep = ((type_T **)stack->ga_data) + stack->ga_len - 1;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4749 common_type(type1, *typep, typep, cctx->ctx_type_list);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4750
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
4751 // jump here from JUMP_ALWAYS or JUMP_AND_KEEP_IF_TRUE
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4752 isn = ((isn_T *)instr->ga_data) + end_idx;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4753 isn->isn_arg.jump.jump_where = instr->ga_len;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4754 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4755
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4756 cctx->ctx_skip = save_skip;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4757 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4758 return OK;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4759 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4760
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4761 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4762 * Toplevel expression.
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4763 * Sets "is_const" (if not NULL) to indicate the value is a constant.
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4764 * Returns OK or FAIL.
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4765 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4766 static int
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4767 compile_expr0_ext(char_u **arg, cctx_T *cctx, int *is_const)
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4768 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4769 ppconst_T ppconst;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4770
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4771 CLEAR_FIELD(ppconst);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4772 if (compile_expr1(arg, cctx, &ppconst) == FAIL)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4773 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4774 clear_ppconst(&ppconst);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4775 return FAIL;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4776 }
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4777 if (is_const != NULL)
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4778 *is_const = ppconst.pp_used > 0 || ppconst.pp_is_const;
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4779 if (generate_ppconst(cctx, &ppconst) == FAIL)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4780 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4781 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4782 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4783
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4784 /*
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4785 * Toplevel expression.
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4786 */
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4787 static int
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4788 compile_expr0(char_u **arg, cctx_T *cctx)
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4789 {
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4790 return compile_expr0_ext(arg, cctx, NULL);
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4791 }
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4792
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4793 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4794 * compile "return [expr]"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4795 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4796 static char_u *
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
4797 compile_return(char_u *arg, int check_return_type, cctx_T *cctx)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4798 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4799 char_u *p = arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4800 garray_T *stack = &cctx->ctx_type_stack;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4801 type_T *stack_type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4802
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4803 if (*p != NUL && *p != '|' && *p != '\n')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4804 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4805 // compile return argument into instructions
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4806 if (compile_expr0(&p, cctx) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4807 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4808
22926
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
4809 if (cctx->ctx_skip != SKIP_YES)
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
4810 {
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
4811 stack_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
23418
681f042ae5ac patch 8.2.2252: Vim9: crash when using lambda without return type in dict
Bram Moolenaar <Bram@vim.org>
parents: 23414
diff changeset
4812 if (check_return_type && (cctx->ctx_ufunc->uf_ret_type == NULL
681f042ae5ac patch 8.2.2252: Vim9: crash when using lambda without return type in dict
Bram Moolenaar <Bram@vim.org>
parents: 23414
diff changeset
4813 || cctx->ctx_ufunc->uf_ret_type == &t_unknown))
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
4814 {
22926
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
4815 cctx->ctx_ufunc->uf_ret_type = stack_type;
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
4816 }
22926
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
4817 else
21160
1a393685e7ce patch 8.2.1131: Vim9: error message for returning a value is not clear
Bram Moolenaar <Bram@vim.org>
parents: 21158
diff changeset
4818 {
22926
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
4819 if (cctx->ctx_ufunc->uf_ret_type->tt_type == VAR_VOID
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
4820 && stack_type->tt_type != VAR_VOID
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
4821 && stack_type->tt_type != VAR_UNKNOWN)
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
4822 {
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
4823 emsg(_(e_returning_value_in_function_without_return_type));
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
4824 return NULL;
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
4825 }
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
4826 if (need_type(stack_type, cctx->ctx_ufunc->uf_ret_type, -1,
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
4827 cctx, FALSE, FALSE) == FAIL)
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
4828 return NULL;
21160
1a393685e7ce patch 8.2.1131: Vim9: error message for returning a value is not clear
Bram Moolenaar <Bram@vim.org>
parents: 21158
diff changeset
4829 }
1a393685e7ce patch 8.2.1131: Vim9: error message for returning a value is not clear
Bram Moolenaar <Bram@vim.org>
parents: 21158
diff changeset
4830 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4831 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4832 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4833 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
4834 // "check_return_type" cannot be TRUE, only used for a lambda which
19860
37c4779ca8f5 patch 8.2.0486: Vim9: some code and error messages not tested
Bram Moolenaar <Bram@vim.org>
parents: 19858
diff changeset
4835 // always has an argument.
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
4836 if (cctx->ctx_ufunc->uf_ret_type->tt_type != VAR_VOID
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
4837 && cctx->ctx_ufunc->uf_ret_type->tt_type != VAR_UNKNOWN)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4838 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
4839 emsg(_(e_missing_return_value));
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4840 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4841 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4842
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4843 // No argument, return zero.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4844 generate_PUSHNR(cctx, 0);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4845 }
22926
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
4846 if (cctx->ctx_skip != SKIP_YES && generate_instr(cctx, ISN_RETURN) == NULL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4847 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4848
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4849 // "return val | endif" is possible
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4850 return skipwhite(p);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4851 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4852
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4853 /*
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4854 * Get a line from the compilation context, compatible with exarg_T getline().
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4855 * Return a pointer to the line in allocated memory.
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4856 * Return NULL for end-of-file or some error.
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4857 */
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4858 static char_u *
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4859 exarg_getline(
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4860 int c UNUSED,
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4861 void *cookie,
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4862 int indent UNUSED,
21883
a427f5f26419 patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents: 21881
diff changeset
4863 getline_opt_T options UNUSED)
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4864 {
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4865 cctx_T *cctx = (cctx_T *)cookie;
21883
a427f5f26419 patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents: 21881
diff changeset
4866 char_u *p;
a427f5f26419 patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents: 21881
diff changeset
4867
a427f5f26419 patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents: 21881
diff changeset
4868 for (;;)
a427f5f26419 patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents: 21881
diff changeset
4869 {
22423
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22415
diff changeset
4870 if (cctx->ctx_lnum >= cctx->ctx_ufunc->uf_lines.ga_len - 1)
21883
a427f5f26419 patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents: 21881
diff changeset
4871 return NULL;
a427f5f26419 patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents: 21881
diff changeset
4872 ++cctx->ctx_lnum;
a427f5f26419 patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents: 21881
diff changeset
4873 p = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum];
a427f5f26419 patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents: 21881
diff changeset
4874 // Comment lines result in NULL pointers, skip them.
a427f5f26419 patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents: 21881
diff changeset
4875 if (p != NULL)
a427f5f26419 patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents: 21881
diff changeset
4876 return vim_strsave(p);
a427f5f26419 patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents: 21881
diff changeset
4877 }
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4878 }
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4879
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4880 /*
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4881 * Compile a nested :def command.
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4882 */
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4883 static char_u *
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4884 compile_nested_function(exarg_T *eap, cctx_T *cctx)
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4885 {
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
4886 int is_global = *eap->arg == 'g' && eap->arg[1] == ':';
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4887 char_u *name_start = eap->arg;
21602
7028f45bf0ea patch 8.2.1351: Vim9: no proper error if using namespace for nested function
Bram Moolenaar <Bram@vim.org>
parents: 21598
diff changeset
4888 char_u *name_end = to_name_end(eap->arg, TRUE);
21598
7b5b9558500a patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents: 21584
diff changeset
4889 char_u *lambda_name;
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4890 ufunc_T *ufunc;
23291
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
4891 int r = FAIL;
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4892
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
4893 if (eap->forceit)
22216
f9b4576a618b patch 8.2.1657: Vim9: no proper error for nested ":def!"
Bram Moolenaar <Bram@vim.org>
parents: 22196
diff changeset
4894 {
f9b4576a618b patch 8.2.1657: Vim9: no proper error for nested ":def!"
Bram Moolenaar <Bram@vim.org>
parents: 22196
diff changeset
4895 emsg(_(e_cannot_use_bang_with_nested_def));
f9b4576a618b patch 8.2.1657: Vim9: no proper error for nested ":def!"
Bram Moolenaar <Bram@vim.org>
parents: 22196
diff changeset
4896 return NULL;
f9b4576a618b patch 8.2.1657: Vim9: no proper error for nested ":def!"
Bram Moolenaar <Bram@vim.org>
parents: 22196
diff changeset
4897 }
f9b4576a618b patch 8.2.1657: Vim9: no proper error for nested ":def!"
Bram Moolenaar <Bram@vim.org>
parents: 22196
diff changeset
4898
22973
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
4899 if (*name_start == '/')
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
4900 {
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
4901 name_end = skip_regexp(name_start + 1, '/', TRUE);
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
4902 if (*name_end == '/')
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
4903 ++name_end;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
4904 eap->nextcmd = check_nextcmd(name_end);
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
4905 }
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
4906 if (name_end == name_start || *skipwhite(name_end) != '(')
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
4907 {
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
4908 if (!ends_excmd2(name_start, name_end))
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
4909 {
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
4910 semsg(_(e_invalid_command_str), eap->cmd);
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
4911 return NULL;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
4912 }
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
4913
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
4914 // "def" or "def Name": list functions
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
4915 if (generate_DEF(cctx, name_start, name_end - name_start) == FAIL)
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
4916 return NULL;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
4917 return eap->nextcmd == NULL ? (char_u *)"" : eap->nextcmd;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
4918 }
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
4919
21602
7028f45bf0ea patch 8.2.1351: Vim9: no proper error if using namespace for nested function
Bram Moolenaar <Bram@vim.org>
parents: 21598
diff changeset
4920 // Only g:Func() can use a namespace.
7028f45bf0ea patch 8.2.1351: Vim9: no proper error if using namespace for nested function
Bram Moolenaar <Bram@vim.org>
parents: 21598
diff changeset
4921 if (name_start[1] == ':' && !is_global)
7028f45bf0ea patch 8.2.1351: Vim9: no proper error if using namespace for nested function
Bram Moolenaar <Bram@vim.org>
parents: 21598
diff changeset
4922 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
4923 semsg(_(e_namespace_not_supported_str), name_start);
21602
7028f45bf0ea patch 8.2.1351: Vim9: no proper error if using namespace for nested function
Bram Moolenaar <Bram@vim.org>
parents: 21598
diff changeset
4924 return NULL;
7028f45bf0ea patch 8.2.1351: Vim9: no proper error if using namespace for nested function
Bram Moolenaar <Bram@vim.org>
parents: 21598
diff changeset
4925 }
21598
7b5b9558500a patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents: 21584
diff changeset
4926 if (check_defined(name_start, name_end - name_start, cctx) == FAIL)
7b5b9558500a patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents: 21584
diff changeset
4927 return NULL;
7b5b9558500a patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents: 21584
diff changeset
4928
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4929 eap->arg = name_end;
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4930 eap->getline = exarg_getline;
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4931 eap->cookie = cctx;
20907
4eeda7139133 patch 8.2.1005: Vim9: using TRUE/FALSE/MAYBE for ctx_skip is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20899
diff changeset
4932 eap->skip = cctx->ctx_skip == SKIP_YES;
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4933 eap->forceit = FALSE;
23291
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
4934 lambda_name = vim_strsave(get_lambda_name());
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
4935 if (lambda_name == NULL)
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
4936 return NULL;
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
4937 ufunc = define_function(eap, lambda_name);
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20419
diff changeset
4938
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20419
diff changeset
4939 if (ufunc == NULL)
23291
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
4940 {
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
4941 r = eap->skip ? OK : FAIL;
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
4942 goto theend;
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
4943 }
20943
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
4944 if (ufunc->uf_def_status == UF_TO_BE_COMPILED
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20419
diff changeset
4945 && compile_def_function(ufunc, TRUE, cctx) == FAIL)
22369
62192fd08e0e patch 8.2.1733: Vim9: memory leaks when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
4946 {
62192fd08e0e patch 8.2.1733: Vim9: memory leaks when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
4947 func_ptr_unref(ufunc);
23291
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
4948 goto theend;
22369
62192fd08e0e patch 8.2.1733: Vim9: memory leaks when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
4949 }
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4950
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
4951 if (is_global)
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
4952 {
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
4953 char_u *func_name = vim_strnsave(name_start + 2,
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
4954 name_end - name_start - 2);
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
4955
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
4956 if (func_name == NULL)
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
4957 r = FAIL;
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
4958 else
23291
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
4959 {
21598
7b5b9558500a patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents: 21584
diff changeset
4960 r = generate_NEWFUNC(cctx, lambda_name, func_name);
23291
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
4961 lambda_name = NULL;
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
4962 }
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
4963 }
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
4964 else
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
4965 {
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
4966 // Define a local variable for the function reference.
22537
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22508
diff changeset
4967 lvar_T *lvar = reserve_local(cctx, name_start, name_end - name_start,
20281
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
4968 TRUE, ufunc->uf_func_type);
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
4969 int block_depth = cctx->ctx_ufunc->uf_block_depth;
22537
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22508
diff changeset
4970
21598
7b5b9558500a patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents: 21584
diff changeset
4971 if (lvar == NULL)
23291
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
4972 goto theend;
21693
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
4973 if (generate_FUNCREF(cctx, ufunc) == FAIL)
23291
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
4974 goto theend;
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
4975 r = generate_STORE(cctx, ISN_STORE, lvar->lv_idx, NULL);
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
4976
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
4977 // copy over the block scope IDs
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
4978 if (block_depth > 0)
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
4979 {
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
4980 ufunc->uf_block_ids = ALLOC_MULT(int, block_depth);
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
4981 if (ufunc->uf_block_ids != NULL)
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
4982 {
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
4983 mch_memmove(ufunc->uf_block_ids, cctx->ctx_ufunc->uf_block_ids,
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
4984 sizeof(int) * block_depth);
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
4985 ufunc->uf_block_depth = block_depth;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
4986 }
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
4987 }
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
4988 }
20305
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4989 // TODO: warning for trailing text?
23291
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
4990 r = OK;
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
4991
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
4992 theend:
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
4993 vim_free(lambda_name);
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
4994 return r == FAIL ? NULL : (char_u *)"";
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4995 }
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4996
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
4997 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4998 * Return the length of an assignment operator, or zero if there isn't one.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4999 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5000 int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5001 assignment_len(char_u *p, int *heredoc)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5002 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5003 if (*p == '=')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5004 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5005 if (p[1] == '<' && p[2] == '<')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5006 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5007 *heredoc = TRUE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5008 return 3;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5009 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5010 return 1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5011 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5012 if (vim_strchr((char_u *)"+-*/%", *p) != NULL && p[1] == '=')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5013 return 2;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5014 if (STRNCMP(p, "..=", 3) == 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5015 return 3;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5016 return 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5017 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5018
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5019 // words that cannot be used as a variable
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5020 static char *reserved[] = {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5021 "true",
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5022 "false",
23497
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
5023 "null",
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5024 NULL
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5025 };
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5026
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
5027 typedef enum {
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
5028 dest_local,
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
5029 dest_option,
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
5030 dest_env,
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
5031 dest_global,
20089
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
5032 dest_buffer,
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
5033 dest_window,
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
5034 dest_tab,
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
5035 dest_vimvar,
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
5036 dest_script,
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
5037 dest_reg,
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5038 dest_expr,
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
5039 } assign_dest_T;
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
5040
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5041 /*
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5042 * Generate the load instruction for "name".
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5043 */
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5044 static void
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5045 generate_loadvar(
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5046 cctx_T *cctx,
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5047 assign_dest_T dest,
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5048 char_u *name,
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5049 lvar_T *lvar,
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5050 type_T *type)
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5051 {
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5052 switch (dest)
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5053 {
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5054 case dest_option:
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5055 // TODO: check the option exists
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5056 generate_LOAD(cctx, ISN_LOADOPT, 0, name, type);
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5057 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5058 case dest_global:
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
5059 if (vim_strchr(name, AUTOLOAD_CHAR) == NULL)
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
5060 generate_LOAD(cctx, ISN_LOADG, 0, name + 2, type);
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
5061 else
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
5062 generate_LOAD(cctx, ISN_LOADAUTO, 0, name, type);
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5063 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5064 case dest_buffer:
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5065 generate_LOAD(cctx, ISN_LOADB, 0, name + 2, type);
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5066 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5067 case dest_window:
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5068 generate_LOAD(cctx, ISN_LOADW, 0, name + 2, type);
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5069 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5070 case dest_tab:
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5071 generate_LOAD(cctx, ISN_LOADT, 0, name + 2, type);
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5072 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5073 case dest_script:
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5074 compile_load_scriptvar(cctx,
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5075 name + (name[1] == ':' ? 2 : 0), NULL, NULL, TRUE);
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5076 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5077 case dest_env:
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5078 // Include $ in the name here
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5079 generate_LOAD(cctx, ISN_LOADENV, 0, name, type);
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5080 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5081 case dest_reg:
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5082 generate_LOAD(cctx, ISN_LOADREG, name[1], NULL, &t_string);
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5083 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5084 case dest_vimvar:
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5085 generate_LOADV(cctx, name + 2, TRUE);
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5086 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5087 case dest_local:
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5088 if (lvar->lv_from_outer)
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5089 generate_LOAD(cctx, ISN_LOADOUTER, lvar->lv_idx,
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5090 NULL, type);
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5091 else
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5092 generate_LOAD(cctx, ISN_LOAD, lvar->lv_idx, NULL, type);
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5093 break;
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5094 case dest_expr:
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5095 // list or dict value should already be on the stack.
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5096 break;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5097 }
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5098 }
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5099
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5100 /*
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5101 * Skip over "[expr]" or ".member".
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5102 * Does not check for any errors.
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5103 */
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5104 static char_u *
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5105 skip_index(char_u *start)
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5106 {
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5107 char_u *p = start;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5108
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5109 if (*p == '[')
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5110 {
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5111 p = skipwhite(p + 1);
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5112 (void)skip_expr(&p, NULL);
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5113 p = skipwhite(p);
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5114 if (*p == ']')
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5115 return p + 1;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5116 return p;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5117 }
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5118 // if (*p == '.')
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5119 return to_name_end(p + 1, TRUE);
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5120 }
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5121
20953
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5122 void
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5123 vim9_declare_error(char_u *name)
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5124 {
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5125 char *scope = "";
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5126
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5127 switch (*name)
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5128 {
20961
0e01976dfd3b patch 8.2.1032: error message for declaring a variable cannot be translated
Bram Moolenaar <Bram@vim.org>
parents: 20955
diff changeset
5129 case 'g': scope = _("global"); break;
0e01976dfd3b patch 8.2.1032: error message for declaring a variable cannot be translated
Bram Moolenaar <Bram@vim.org>
parents: 20955
diff changeset
5130 case 'b': scope = _("buffer"); break;
0e01976dfd3b patch 8.2.1032: error message for declaring a variable cannot be translated
Bram Moolenaar <Bram@vim.org>
parents: 20955
diff changeset
5131 case 'w': scope = _("window"); break;
0e01976dfd3b patch 8.2.1032: error message for declaring a variable cannot be translated
Bram Moolenaar <Bram@vim.org>
parents: 20955
diff changeset
5132 case 't': scope = _("tab"); break;
0e01976dfd3b patch 8.2.1032: error message for declaring a variable cannot be translated
Bram Moolenaar <Bram@vim.org>
parents: 20955
diff changeset
5133 case 'v': scope = "v:"; break;
21789
f84625b961a8 patch 8.2.1444: error messages are spread out and names can be confusing
Bram Moolenaar <Bram@vim.org>
parents: 21771
diff changeset
5134 case '$': semsg(_(e_cannot_declare_an_environment_variable), name);
21610
586241ee8096 patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents: 21604
diff changeset
5135 return;
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5136 case '&': semsg(_(e_cannot_declare_an_option), name);
21610
586241ee8096 patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents: 21604
diff changeset
5137 return;
21909
a211bca98bc3 patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents: 21903
diff changeset
5138 case '@': semsg(_(e_cannot_declare_a_register_str), name);
21610
586241ee8096 patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents: 21604
diff changeset
5139 return;
20961
0e01976dfd3b patch 8.2.1032: error message for declaring a variable cannot be translated
Bram Moolenaar <Bram@vim.org>
parents: 20955
diff changeset
5140 default: return;
20953
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5141 }
21789
f84625b961a8 patch 8.2.1444: error messages are spread out and names can be confusing
Bram Moolenaar <Bram@vim.org>
parents: 21771
diff changeset
5142 semsg(_(e_cannot_declare_a_scope_variable), scope, name);
20953
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5143 }
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5144
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5145 /*
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5146 * For one assignment figure out the type of destination. Return it in "dest".
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5147 * When not recognized "dest" is not set.
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5148 * For an option "opt_flags" is set.
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5149 * For a v:var "vimvaridx" is set.
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5150 * "type" is set to the destination type if known, unchanted otherwise.
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5151 * Return FAIL if an error message was given.
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5152 */
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5153 static int
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5154 get_var_dest(
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5155 char_u *name,
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5156 assign_dest_T *dest,
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5157 int cmdidx,
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5158 int *opt_flags,
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5159 int *vimvaridx,
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5160 type_T **type,
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5161 cctx_T *cctx)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5162 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5163 char_u *p;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5164
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5165 if (*name == '&')
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5166 {
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5167 int cc;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5168 long numval;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5169 getoption_T opt_type;
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5170
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5171 *dest = dest_option;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5172 if (cmdidx == CMD_final || cmdidx == CMD_const)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5173 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5174 emsg(_(e_const_option));
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5175 return FAIL;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5176 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5177 p = name;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5178 p = find_option_end(&p, opt_flags);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5179 if (p == NULL)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5180 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5181 // cannot happen?
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5182 emsg(_(e_letunexp));
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5183 return FAIL;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5184 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5185 cc = *p;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5186 *p = NUL;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5187 opt_type = get_option_value(skip_option_env_lead(name),
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5188 &numval, NULL, *opt_flags);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5189 *p = cc;
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5190 switch (opt_type)
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5191 {
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5192 case gov_unknown:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5193 semsg(_(e_unknown_option), name);
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5194 return FAIL;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5195 case gov_string:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5196 case gov_hidden_string:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5197 *type = &t_string;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5198 break;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5199 case gov_bool:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5200 case gov_hidden_bool:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5201 *type = &t_bool;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5202 break;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5203 case gov_number:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5204 case gov_hidden_number:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5205 *type = &t_number;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5206 break;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5207 }
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5208 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5209 else if (*name == '$')
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5210 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5211 *dest = dest_env;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5212 *type = &t_string;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5213 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5214 else if (*name == '@')
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5215 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5216 if (!valid_yank_reg(name[1], FALSE) || name[1] == '.')
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5217 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5218 emsg_invreg(name[1]);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5219 return FAIL;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5220 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5221 *dest = dest_reg;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5222 *type = &t_string;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5223 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5224 else if (STRNCMP(name, "g:", 2) == 0)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5225 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5226 *dest = dest_global;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5227 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5228 else if (STRNCMP(name, "b:", 2) == 0)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5229 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5230 *dest = dest_buffer;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5231 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5232 else if (STRNCMP(name, "w:", 2) == 0)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5233 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5234 *dest = dest_window;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5235 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5236 else if (STRNCMP(name, "t:", 2) == 0)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5237 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5238 *dest = dest_tab;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5239 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5240 else if (STRNCMP(name, "v:", 2) == 0)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5241 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5242 typval_T *vtv;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5243 int di_flags;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5244
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5245 *vimvaridx = find_vim_var(name + 2, &di_flags);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5246 if (*vimvaridx < 0)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5247 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5248 semsg(_(e_variable_not_found_str), name);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5249 return FAIL;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5250 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5251 // We use the current value of "sandbox" here, is that OK?
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5252 if (var_check_ro(di_flags, name, FALSE))
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5253 return FAIL;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5254 *dest = dest_vimvar;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5255 vtv = get_vim_var_tv(*vimvaridx);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5256 *type = typval2type_vimvar(vtv, cctx->ctx_type_list);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5257 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5258 return OK;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5259 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5260
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5261 /*
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5262 * Generate a STORE instruction for "dest", not being "dest_local".
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5263 * Return FAIL when out of memory.
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5264 */
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5265 static int
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5266 generate_store_var(
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5267 cctx_T *cctx,
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5268 assign_dest_T dest,
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5269 int opt_flags,
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5270 int vimvaridx,
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5271 int scriptvar_idx,
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5272 int scriptvar_sid,
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5273 type_T *type,
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5274 char_u *name)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5275 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5276 switch (dest)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5277 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5278 case dest_option:
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5279 return generate_STOREOPT(cctx, skip_option_env_lead(name),
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5280 opt_flags);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5281 case dest_global:
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5282 // include g: with the name, easier to execute that way
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
5283 return generate_STORE(cctx, vim_strchr(name, AUTOLOAD_CHAR) == NULL
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
5284 ? ISN_STOREG : ISN_STOREAUTO, 0, name);
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5285 case dest_buffer:
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5286 // include b: with the name, easier to execute that way
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5287 return generate_STORE(cctx, ISN_STOREB, 0, name);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5288 case dest_window:
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5289 // include w: with the name, easier to execute that way
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5290 return generate_STORE(cctx, ISN_STOREW, 0, name);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5291 case dest_tab:
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5292 // include t: with the name, easier to execute that way
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5293 return generate_STORE(cctx, ISN_STORET, 0, name);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5294 case dest_env:
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5295 return generate_STORE(cctx, ISN_STOREENV, 0, name + 1);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5296 case dest_reg:
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5297 return generate_STORE(cctx, ISN_STOREREG, name[1], NULL);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5298 case dest_vimvar:
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5299 return generate_STORE(cctx, ISN_STOREV, vimvaridx, NULL);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5300 case dest_script:
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5301 if (scriptvar_idx < 0)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5302 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5303 char_u *name_s = name;
23114
462774c327df patch 8.2.2103: Vim9: unreachable code
Bram Moolenaar <Bram@vim.org>
parents: 23110
diff changeset
5304 int r;
462774c327df patch 8.2.2103: Vim9: unreachable code
Bram Moolenaar <Bram@vim.org>
parents: 23110
diff changeset
5305
462774c327df patch 8.2.2103: Vim9: unreachable code
Bram Moolenaar <Bram@vim.org>
parents: 23110
diff changeset
5306 // "s:" is included in the name.
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5307 r = generate_OLDSCRIPT(cctx, ISN_STORES, name_s,
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5308 scriptvar_sid, type);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5309 if (name_s != name)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5310 vim_free(name_s);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5311 return r;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5312 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5313 return generate_VIM9SCRIPT(cctx, ISN_STORESCRIPT,
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5314 scriptvar_sid, scriptvar_idx, type);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5315 case dest_local:
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5316 case dest_expr:
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5317 // cannot happen
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5318 break;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5319 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5320 return FAIL;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5321 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5322
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5323 /*
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5324 * Compile declaration and assignment:
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
5325 * "let name"
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
5326 * "var name = expr"
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
5327 * "final name = expr"
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
5328 * "const name = expr"
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
5329 * "name = expr"
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
5330 * "arg" points to "name".
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5331 * Return NULL for an error.
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5332 * Return "arg" if it does not look like a variable list.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5333 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5334 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5335 compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5336 {
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5337 char_u *var_start;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5338 char_u *p;
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5339 char_u *end = arg;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5340 char_u *ret = NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5341 int var_count = 0;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5342 int var_idx;
21576
f4252efe370e patch 8.2.1338: Vim9: assigning to script-local variable doesn't check type
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
5343 int scriptvar_sid = 0;
f4252efe370e patch 8.2.1338: Vim9: assigning to script-local variable doesn't check type
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
5344 int scriptvar_idx = -1;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5345 int semicolon = 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5346 garray_T *instr = &cctx->ctx_instr;
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5347 garray_T *stack = &cctx->ctx_type_stack;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5348 char_u *op;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5349 int oplen = 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5350 int heredoc = FALSE;
19872
8a7bede7b138 patch 8.2.0492: Vim9: some error messages not tested
Bram Moolenaar <Bram@vim.org>
parents: 19866
diff changeset
5351 type_T *type = &t_any;
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5352 type_T *member_type = &t_any;
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5353 type_T *rhs_type = &t_any;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5354 char_u *name = NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5355 char_u *sp;
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
5356 int is_decl = cmdidx == CMD_let || cmdidx == CMD_var
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
5357 || cmdidx == CMD_final || cmdidx == CMD_const;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5358
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5359 // Skip over the "var" or "[var, var]" to get to any "=".
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5360 p = skip_var_list(arg, TRUE, &var_count, &semicolon, TRUE);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5361 if (p == NULL)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5362 return *arg == '[' ? arg : NULL;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5363
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5364 if (var_count > 0 && is_decl)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5365 {
21421
0f0fee4122d3 patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents: 21411
diff changeset
5366 // TODO: should we allow this, and figure out type inference from list
0f0fee4122d3 patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents: 21411
diff changeset
5367 // members?
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5368 emsg(_(e_cannot_use_list_for_declaration));
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5369 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5370 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5371
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5372 sp = p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5373 p = skipwhite(p);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5374 op = p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5375 oplen = assignment_len(p, &heredoc);
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5376
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5377 if (var_count > 0 && oplen == 0)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5378 // can be something like "[1, 2]->func()"
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5379 return arg;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5380
23052
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
5381 if (oplen > 0 && (!VIM_ISWHITE(*sp) || !IS_WHITE_OR_NUL(op[oplen])))
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5382 {
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
5383 error_white_both(op, oplen);
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5384 return NULL;
20355
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20349
diff changeset
5385 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5386
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5387 if (heredoc)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5388 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5389 list_T *l;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5390 listitem_T *li;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5391
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5392 // [let] varname =<< [trim] {end}
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5393 eap->getline = exarg_getline;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5394 eap->cookie = cctx;
20045
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 20023
diff changeset
5395 l = heredoc_get(eap, op + 3, FALSE);
22413
66d1131a7eff patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
5396 if (l == NULL)
66d1131a7eff patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
5397 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5398
22343
9f5a84baa464 patch 8.2.1720: Vim9: memory leak with heredoc that isn't executed
Bram Moolenaar <Bram@vim.org>
parents: 22341
diff changeset
5399 if (cctx->ctx_skip != SKIP_YES)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5400 {
22343
9f5a84baa464 patch 8.2.1720: Vim9: memory leak with heredoc that isn't executed
Bram Moolenaar <Bram@vim.org>
parents: 22341
diff changeset
5401 // Push each line and the create the list.
9f5a84baa464 patch 8.2.1720: Vim9: memory leak with heredoc that isn't executed
Bram Moolenaar <Bram@vim.org>
parents: 22341
diff changeset
5402 FOR_ALL_LIST_ITEMS(l, li)
9f5a84baa464 patch 8.2.1720: Vim9: memory leak with heredoc that isn't executed
Bram Moolenaar <Bram@vim.org>
parents: 22341
diff changeset
5403 {
9f5a84baa464 patch 8.2.1720: Vim9: memory leak with heredoc that isn't executed
Bram Moolenaar <Bram@vim.org>
parents: 22341
diff changeset
5404 generate_PUSHS(cctx, li->li_tv.vval.v_string);
9f5a84baa464 patch 8.2.1720: Vim9: memory leak with heredoc that isn't executed
Bram Moolenaar <Bram@vim.org>
parents: 22341
diff changeset
5405 li->li_tv.vval.v_string = NULL;
9f5a84baa464 patch 8.2.1720: Vim9: memory leak with heredoc that isn't executed
Bram Moolenaar <Bram@vim.org>
parents: 22341
diff changeset
5406 }
9f5a84baa464 patch 8.2.1720: Vim9: memory leak with heredoc that isn't executed
Bram Moolenaar <Bram@vim.org>
parents: 22341
diff changeset
5407 generate_NEWLIST(cctx, l->lv_len);
9f5a84baa464 patch 8.2.1720: Vim9: memory leak with heredoc that isn't executed
Bram Moolenaar <Bram@vim.org>
parents: 22341
diff changeset
5408 type = &t_list_string;
9f5a84baa464 patch 8.2.1720: Vim9: memory leak with heredoc that isn't executed
Bram Moolenaar <Bram@vim.org>
parents: 22341
diff changeset
5409 member_type = &t_list_string;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5410 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5411 list_free(l);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5412 p += STRLEN(p);
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5413 end = p;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5414 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5415 else if (var_count > 0)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5416 {
23052
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
5417 char_u *wp;
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
5418
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5419 // for "[var, var] = expr" evaluate the expression here, loop over the
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5420 // list of variables below.
23052
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
5421 // A line break may follow the "=".
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
5422
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
5423 wp = op + oplen;
23122
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23114
diff changeset
5424 if (may_get_next_line_error(wp, &p, cctx) == FAIL)
23052
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
5425 return FAIL;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5426 if (compile_expr0(&p, cctx) == FAIL)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5427 return NULL;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5428 end = p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5429
20907
4eeda7139133 patch 8.2.1005: Vim9: using TRUE/FALSE/MAYBE for ctx_skip is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20899
diff changeset
5430 if (cctx->ctx_skip != SKIP_YES)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5431 {
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5432 type_T *stacktype;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5433
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19934
diff changeset
5434 stacktype = stack->ga_len == 0 ? &t_void
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19934
diff changeset
5435 : ((type_T **)stack->ga_data)[stack->ga_len - 1];
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5436 if (stacktype->tt_type == VAR_VOID)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5437 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5438 emsg(_(e_cannot_use_void_value));
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5439 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5440 }
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5441 if (need_type(stacktype, &t_list_any, -1, cctx,
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5442 FALSE, FALSE) == FAIL)
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5443 goto theend;
21371
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21353
diff changeset
5444 // TODO: check the length of a constant list here
20871
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
5445 generate_CHECKLEN(cctx, semicolon ? var_count - 1 : var_count,
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
5446 semicolon);
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5447 if (stacktype->tt_member != NULL)
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5448 rhs_type = stacktype->tt_member;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5449 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5450 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5451
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5452 /*
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5453 * Loop over variables in "[var, var] = expr".
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5454 * For "var = expr" and "let var: type" this is done only once.
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5455 */
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5456 if (var_count > 0)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5457 var_start = skipwhite(arg + 1); // skip over the "["
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5458 else
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5459 var_start = arg;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5460 for (var_idx = 0; var_idx == 0 || var_idx < var_count; var_idx++)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5461 {
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5462 char_u *var_end;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5463 char_u *dest_end;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5464 size_t varlen;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5465 int new_local = FALSE;
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5466 assign_dest_T dest = dest_local;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5467 int opt_flags = 0;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5468 int vimvaridx = -1;
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
5469 lvar_T local_lvar;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5470 lvar_T *lvar = NULL;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5471 lvar_T arg_lvar;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5472 int has_type = FALSE;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5473 int has_index = FALSE;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5474 int instr_count = -1;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5475
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5476 // "dest_end" is the end of the destination, including "[expr]" or
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5477 // ".name".
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5478 // "var_end" is the end of the variable/option/etc. name.
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5479 dest_end = skip_var_one(var_start, FALSE);
21614
d0128ecd4341 patch 8.2.1357: Vim9: cannot assign to / register
Bram Moolenaar <Bram@vim.org>
parents: 21612
diff changeset
5480 if (*var_start == '@')
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5481 var_end = var_start + 2;
21614
d0128ecd4341 patch 8.2.1357: Vim9: cannot assign to / register
Bram Moolenaar <Bram@vim.org>
parents: 21612
diff changeset
5482 else
d0128ecd4341 patch 8.2.1357: Vim9: cannot assign to / register
Bram Moolenaar <Bram@vim.org>
parents: 21612
diff changeset
5483 {
21937
b931df03adcc patch 8.2.1518: Vim9: cannot assign to local option
Bram Moolenaar <Bram@vim.org>
parents: 21931
diff changeset
5484 // skip over the leading "&", "&l:", "&g:" and "$"
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5485 var_end = skip_option_env_lead(var_start);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5486 var_end = to_name_end(var_end, TRUE);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5487 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5488
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5489 // "a: type" is declaring variable "a" with a type, not dict "a:".
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5490 if (is_decl && dest_end == var_start + 2 && dest_end[-1] == ':')
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5491 --dest_end;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5492 if (is_decl && var_end == var_start + 2 && var_end[-1] == ':')
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5493 --var_end;
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5494
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5495 // compute the length of the destination without "[expr]" or ".name"
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5496 varlen = var_end - var_start;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5497 vim_free(name);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5498 name = vim_strnsave(var_start, varlen);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5499 if (name == NULL)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5500 return NULL;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5501 if (!heredoc)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5502 type = &t_any;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5503
20907
4eeda7139133 patch 8.2.1005: Vim9: using TRUE/FALSE/MAYBE for ctx_skip is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20899
diff changeset
5504 if (cctx->ctx_skip != SKIP_YES)
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5505 {
21610
586241ee8096 patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents: 21604
diff changeset
5506 int declare_error = FALSE;
586241ee8096 patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents: 21604
diff changeset
5507
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5508 if (get_var_dest(name, &dest, cmdidx, &opt_flags,
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5509 &vimvaridx, &type, cctx) == FAIL)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5510 goto theend;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5511 if (dest != dest_local)
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5512 {
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5513 // Specific kind of variable recognized.
21610
586241ee8096 patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents: 21604
diff changeset
5514 declare_error = is_decl;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5515 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5516 else
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5517 {
21576
f4252efe370e patch 8.2.1338: Vim9: assigning to script-local variable doesn't check type
Bram Moolenaar <Bram@vim.org>
parents: 21564
diff changeset
5518 int idx;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5519
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5520 // No specific kind of variable recognized, just a name.
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5521 for (idx = 0; reserved[idx] != NULL; ++idx)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5522 if (STRCMP(reserved[idx], name) == 0)
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19934
diff changeset
5523 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5524 semsg(_(e_cannot_use_reserved_name), name);
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19934
diff changeset
5525 goto theend;
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19934
diff changeset
5526 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5527
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
5528
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
5529 if (lookup_local(var_start, varlen, &local_lvar, cctx) == OK)
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
5530 lvar = &local_lvar;
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
5531 else
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5532 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5533 CLEAR_FIELD(arg_lvar);
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
5534 if (arg_exists(var_start, varlen,
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5535 &arg_lvar.lv_idx, &arg_lvar.lv_type,
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5536 &arg_lvar.lv_from_outer, cctx) == OK)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5537 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5538 if (is_decl)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5539 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5540 semsg(_(e_str_is_used_as_argument), name);
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5541 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5542 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5543 lvar = &arg_lvar;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5544 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5545 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5546 if (lvar != NULL)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5547 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5548 if (is_decl)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5549 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5550 semsg(_(e_variable_already_declared), name);
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5551 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5552 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5553 }
21646
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5554 else
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5555 {
21646
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5556 int script_namespace = varlen > 1
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5557 && STRNCMP(var_start, "s:", 2) == 0;
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5558 int script_var = (script_namespace
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
5559 ? script_var_exists(var_start + 2, varlen - 2,
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
5560 FALSE, cctx)
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
5561 : script_var_exists(var_start, varlen,
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
5562 TRUE, cctx)) == OK;
21646
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5563 imported_T *import =
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5564 find_imported(var_start, varlen, cctx);
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5565
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5566 if (script_namespace || script_var || import != NULL)
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19934
diff changeset
5567 {
21646
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5568 char_u *rawname = name + (name[1] == ':' ? 2 : 0);
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5569
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5570 if (is_decl)
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5571 {
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5572 if (script_namespace)
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5573 semsg(_(e_cannot_declare_script_variable_in_function),
21646
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5574 name);
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5575 else
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5576 semsg(_(e_variable_already_declared_in_script),
21540
8e278698b1fe patch 8.2.1320: Vim9: cannot declare some single letter variables
Bram Moolenaar <Bram@vim.org>
parents: 21516
diff changeset
5577 name);
21646
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5578 goto theend;
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5579 }
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5580 else if (cctx->ctx_ufunc->uf_script_ctx_version
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5581 == SCRIPT_VERSION_VIM9
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5582 && script_namespace
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5583 && !script_var && import == NULL)
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5584 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5585 semsg(_(e_unknown_variable_str), name);
21646
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5586 goto theend;
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5587 }
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5588
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5589 dest = dest_script;
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5590
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5591 // existing script-local variables should have a type
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5592 scriptvar_sid = current_sctx.sc_sid;
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5593 if (import != NULL)
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5594 scriptvar_sid = import->imp_sid;
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
5595 if (SCRIPT_ID_VALID(scriptvar_sid))
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
5596 {
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
5597 scriptvar_idx = get_script_item_idx(scriptvar_sid,
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
5598 rawname, TRUE, cctx);
22431
685909aa5641 patch 8.2.1764: Vim9: no error when assigning to script var with wrong type
Bram Moolenaar <Bram@vim.org>
parents: 22423
diff changeset
5599 if (scriptvar_idx >= 0)
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
5600 {
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
5601 scriptitem_T *si = SCRIPT_ITEM(scriptvar_sid);
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
5602 svar_T *sv =
21646
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5603 ((svar_T *)si->sn_var_vals.ga_data)
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5604 + scriptvar_idx;
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
5605 type = sv->sv_type;
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
5606 }
21646
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5607 }
a640bc762196 patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents: 21630
diff changeset
5608 }
21683
bb4f55d20951 patch 8.2.1391: Vim9: no error for shadowing a script function
Bram Moolenaar <Bram@vim.org>
parents: 21681
diff changeset
5609 else if (check_defined(var_start, varlen, cctx) == FAIL)
bb4f55d20951 patch 8.2.1391: Vim9: no error for shadowing a script function
Bram Moolenaar <Bram@vim.org>
parents: 21681
diff changeset
5610 goto theend;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5611 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5612 }
21610
586241ee8096 patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents: 21604
diff changeset
5613
586241ee8096 patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents: 21604
diff changeset
5614 if (declare_error)
586241ee8096 patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents: 21604
diff changeset
5615 {
586241ee8096 patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents: 21604
diff changeset
5616 vim9_declare_error(name);
586241ee8096 patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents: 21604
diff changeset
5617 goto theend;
586241ee8096 patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents: 21604
diff changeset
5618 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5619 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5620
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5621 // handle "a:name" as a name, not index "name" on "a"
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5622 if (varlen > 1 || var_start[varlen] != ':')
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5623 var_end = dest_end;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5624
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5625 if (dest != dest_option)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5626 {
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5627 if (is_decl && *var_end == ':')
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5628 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5629 // parse optional type: "let var: type = expr"
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5630 if (!VIM_ISWHITE(var_end[1]))
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5631 {
21909
a211bca98bc3 patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents: 21903
diff changeset
5632 semsg(_(e_white_space_required_after_str), ":");
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5633 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5634 }
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5635 p = skipwhite(var_end + 1);
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
5636 type = parse_type(&p, cctx->ctx_type_list, TRUE);
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
5637 if (type == NULL)
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
5638 goto theend;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5639 has_type = TRUE;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5640 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5641 else if (lvar != NULL)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5642 type = lvar->lv_type;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5643 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5644
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5645 if (oplen == 3 && !heredoc && dest != dest_global
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5646 && type->tt_type != VAR_STRING
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5647 && type->tt_type != VAR_ANY)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5648 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5649 emsg(_(e_can_only_concatenate_to_string));
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5650 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5651 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5652
20907
4eeda7139133 patch 8.2.1005: Vim9: using TRUE/FALSE/MAYBE for ctx_skip is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20899
diff changeset
5653 if (lvar == NULL && dest == dest_local && cctx->ctx_skip != SKIP_YES)
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5654 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5655 if (oplen > 1 && !heredoc)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5656 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5657 // +=, /=, etc. require an existing variable
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5658 semsg(_(e_cannot_use_operator_on_new_variable), name);
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5659 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5660 }
23450
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23446
diff changeset
5661 if (!is_decl)
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23446
diff changeset
5662 {
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23446
diff changeset
5663 semsg(_(e_unknown_variable_str), name);
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23446
diff changeset
5664 goto theend;
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23446
diff changeset
5665 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5666
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5667 // new local variable
21691
f41c646cb8b9 patch 8.2.1395: Vim9: no error if declaring a funcref with lower case letter
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
5668 if ((type->tt_type == VAR_FUNC || type->tt_type == VAR_PARTIAL)
f41c646cb8b9 patch 8.2.1395: Vim9: no error if declaring a funcref with lower case letter
Bram Moolenaar <Bram@vim.org>
parents: 21689
diff changeset
5669 && var_wrong_func_name(name, TRUE))
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5670 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5671 lvar = reserve_local(cctx, var_start, varlen,
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
5672 cmdidx == CMD_final || cmdidx == CMD_const, type);
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5673 if (lvar == NULL)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5674 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5675 new_local = TRUE;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5676 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5677
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5678 member_type = type;
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5679 if (dest_end > var_start + varlen)
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5680 {
22906
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5681 // Something follows after the variable: "var[idx]" or "var.key".
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5682 // TODO: should we also handle "->func()" here?
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5683 if (is_decl)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5684 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5685 emsg(_(e_cannot_use_index_when_declaring_variable));
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5686 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5687 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5688
22906
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5689 if (var_start[varlen] == '[' || var_start[varlen] == '.')
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5690 {
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5691 char_u *after = var_start + varlen;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5692
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5693 // Only the last index is used below, if there are others
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5694 // before it generate code for the expression. Thus for
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5695 // "ll[1][2]" the expression is "ll[1]" and "[2]" is the index.
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5696 for (;;)
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5697 {
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5698 p = skip_index(after);
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5699 if (*p != '[' && *p != '.')
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5700 break;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5701 after = p;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5702 }
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5703 if (after > var_start + varlen)
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5704 {
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5705 varlen = after - var_start;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5706 dest = dest_expr;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5707 // We don't know the type before evaluating the expression,
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5708 // use "any" until then.
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5709 type = &t_any;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5710 }
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5711
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5712 has_index = TRUE;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5713 if (type->tt_member == NULL)
21578
7417cb54cb24 patch 8.2.1339: Vim9: assigning to global dict variable doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
5714 member_type = &t_any;
7417cb54cb24 patch 8.2.1339: Vim9: assigning to global dict variable doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
5715 else
7417cb54cb24 patch 8.2.1339: Vim9: assigning to global dict variable doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
5716 member_type = type->tt_member;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5717 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5718 else
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5719 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5720 semsg("Not supported yet: %s", var_start);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5721 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5722 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5723 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5724 else if (lvar == &arg_lvar)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5725 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5726 semsg(_(e_cannot_assign_to_argument), name);
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5727 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5728 }
22266
23f5750146d9 patch 8.2.1682: Vim9: const works in an unexpected way
Bram Moolenaar <Bram@vim.org>
parents: 22260
diff changeset
5729 if (!is_decl && lvar != NULL && lvar->lv_const && !has_index)
23f5750146d9 patch 8.2.1682: Vim9: const works in an unexpected way
Bram Moolenaar <Bram@vim.org>
parents: 22260
diff changeset
5730 {
23f5750146d9 patch 8.2.1682: Vim9: const works in an unexpected way
Bram Moolenaar <Bram@vim.org>
parents: 22260
diff changeset
5731 semsg(_(e_cannot_assign_to_constant), name);
23f5750146d9 patch 8.2.1682: Vim9: const works in an unexpected way
Bram Moolenaar <Bram@vim.org>
parents: 22260
diff changeset
5732 goto theend;
23f5750146d9 patch 8.2.1682: Vim9: const works in an unexpected way
Bram Moolenaar <Bram@vim.org>
parents: 22260
diff changeset
5733 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5734
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5735 if (!heredoc)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5736 {
20907
4eeda7139133 patch 8.2.1005: Vim9: using TRUE/FALSE/MAYBE for ctx_skip is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20899
diff changeset
5737 if (cctx->ctx_skip == SKIP_YES)
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5738 {
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5739 if (oplen > 0 && var_count == 0)
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5740 {
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5741 // skip over the "=" and the expression
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5742 p = skipwhite(op + oplen);
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5743 compile_expr0(&p, cctx);
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5744 }
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5745 }
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5746 else if (oplen > 0)
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5747 {
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5748 int is_const = FALSE;
23070
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23068
diff changeset
5749 char_u *wp;
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5750
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5751 // For "var = expr" evaluate the expression.
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5752 if (var_count == 0)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5753 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5754 int r;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5755
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5756 // for "+=", "*=", "..=" etc. first load the current value
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5757 if (*op != '=')
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5758 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5759 generate_loadvar(cctx, dest, name, lvar, type);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5760
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5761 if (has_index)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5762 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5763 // TODO: get member from list or dict
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5764 emsg("Index with operation not supported yet");
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5765 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5766 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5767 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5768
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5769 // Compile the expression. Temporarily hide the new local
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5770 // variable here, it is not available to this expression.
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5771 if (new_local)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5772 --cctx->ctx_locals.ga_len;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5773 instr_count = instr->ga_len;
23070
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23068
diff changeset
5774 wp = op + oplen;
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23068
diff changeset
5775 if (may_get_next_line_error(wp, &p, cctx) == FAIL)
23082
2120e4b40e12 patch 8.2.2087: Vim9: memory leak when statement is truncated
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
5776 {
2120e4b40e12 patch 8.2.2087: Vim9: memory leak when statement is truncated
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
5777 if (new_local)
2120e4b40e12 patch 8.2.2087: Vim9: memory leak when statement is truncated
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
5778 ++cctx->ctx_locals.ga_len;
23070
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23068
diff changeset
5779 goto theend;
23082
2120e4b40e12 patch 8.2.2087: Vim9: memory leak when statement is truncated
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
5780 }
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5781 r = compile_expr0_ext(&p, cctx, &is_const);
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5782 if (new_local)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5783 ++cctx->ctx_locals.ga_len;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5784 if (r == FAIL)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5785 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5786 }
20871
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
5787 else if (semicolon && var_idx == var_count - 1)
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
5788 {
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
5789 // For "[var; var] = expr" get the rest of the list
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
5790 if (generate_SLICE(cctx, var_count - 1) == FAIL)
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
5791 goto theend;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
5792 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5793 else
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5794 {
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5795 // For "[var, var] = expr" get the "var_idx" item from the
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5796 // list.
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5797 if (generate_GETITEM(cctx, var_idx) == FAIL)
23070
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23068
diff changeset
5798 goto theend;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5799 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5800
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5801 rhs_type = stack->ga_len == 0 ? &t_void
21387
8d58cbb07a12 patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents: 21385
diff changeset
5802 : ((type_T **)stack->ga_data)[stack->ga_len - 1];
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5803 if (lvar != NULL && (is_decl || !has_type))
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5804 {
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5805 if ((rhs_type->tt_type == VAR_FUNC
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5806 || rhs_type->tt_type == VAR_PARTIAL)
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
5807 && var_wrong_func_name(name, TRUE))
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
5808 goto theend;
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
5809
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5810 if (new_local && !has_type)
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5811 {
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5812 if (rhs_type->tt_type == VAR_VOID)
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5813 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5814 emsg(_(e_cannot_use_void_value));
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5815 goto theend;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5816 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5817 else
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5818 {
22363
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22343
diff changeset
5819 // An empty list or dict has a &t_unknown member,
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5820 // for a variable that implies &t_any.
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5821 if (rhs_type == &t_list_empty)
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5822 lvar->lv_type = &t_list_any;
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5823 else if (rhs_type == &t_dict_empty)
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5824 lvar->lv_type = &t_dict_any;
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5825 else if (rhs_type == &t_unknown)
22363
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22343
diff changeset
5826 lvar->lv_type = &t_any;
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5827 else
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5828 lvar->lv_type = rhs_type;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5829 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5830 }
21881
675bf9475fff patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
5831 else if (*op == '=')
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5832 {
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5833 type_T *use_type = lvar->lv_type;
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5834
22274
1634ca41e4d3 patch 8.2.1686: Vim9: "const!" not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 22272
diff changeset
5835 // without operator check type here, otherwise below
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5836 if (has_index)
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5837 use_type = member_type;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5838 if (need_type(rhs_type, use_type, -1, cctx,
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5839 FALSE, is_const) == FAIL)
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5840 goto theend;
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5841 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5842 }
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5843 else if (*p != '=' && need_type(rhs_type, member_type, -1,
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5844 cctx, FALSE, FALSE) == FAIL)
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5845 goto theend;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5846 }
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
5847 else if (cmdidx == CMD_final)
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
5848 {
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
5849 emsg(_(e_final_requires_a_value));
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
5850 goto theend;
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
5851 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5852 else if (cmdidx == CMD_const)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5853 {
21789
f84625b961a8 patch 8.2.1444: error messages are spread out and names can be confusing
Bram Moolenaar <Bram@vim.org>
parents: 21771
diff changeset
5854 emsg(_(e_const_requires_a_value));
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5855 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5856 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5857 else if (!has_type || dest == dest_option)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5858 {
21789
f84625b961a8 patch 8.2.1444: error messages are spread out and names can be confusing
Bram Moolenaar <Bram@vim.org>
parents: 21771
diff changeset
5859 emsg(_(e_type_or_initialization_required));
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
5860 goto theend;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5861 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5862 else
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5863 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5864 // variables are always initialized
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5865 if (ga_grow(instr, 1) == FAIL)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5866 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5867 switch (member_type->tt_type)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5868 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5869 case VAR_BOOL:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5870 generate_PUSHBOOL(cctx, VVAL_FALSE);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5871 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5872 case VAR_FLOAT:
19336
1cd6eab65ce0 patch 8.2.0226: compiling for loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
5873 #ifdef FEAT_FLOAT
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5874 generate_PUSHF(cctx, 0.0);
19336
1cd6eab65ce0 patch 8.2.0226: compiling for loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
5875 #endif
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5876 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5877 case VAR_STRING:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5878 generate_PUSHS(cctx, NULL);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5879 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5880 case VAR_BLOB:
22637
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
5881 generate_PUSHBLOB(cctx, blob_alloc());
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5882 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5883 case VAR_FUNC:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5884 generate_PUSHFUNC(cctx, NULL, &t_func_void);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5885 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5886 case VAR_LIST:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5887 generate_NEWLIST(cctx, 0);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5888 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5889 case VAR_DICT:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5890 generate_NEWDICT(cctx, 0);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5891 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5892 case VAR_JOB:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5893 generate_PUSHJOB(cctx, NULL);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5894 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5895 case VAR_CHANNEL:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5896 generate_PUSHCHANNEL(cctx, NULL);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5897 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5898 case VAR_NUMBER:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5899 case VAR_UNKNOWN:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5900 case VAR_ANY:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5901 case VAR_PARTIAL:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5902 case VAR_VOID:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5903 case VAR_SPECIAL: // cannot happen
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5904 generate_PUSHNR(cctx, 0);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5905 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5906 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5907 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5908 if (var_count == 0)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5909 end = p;
19336
1cd6eab65ce0 patch 8.2.0226: compiling for loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
5910 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5911
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5912 // no need to parse more when skipping
20907
4eeda7139133 patch 8.2.1005: Vim9: using TRUE/FALSE/MAYBE for ctx_skip is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20899
diff changeset
5913 if (cctx->ctx_skip == SKIP_YES)
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5914 break;
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
5915
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5916 if (oplen > 0 && *op != '=')
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5917 {
21881
675bf9475fff patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
5918 type_T *expected;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5919 type_T *stacktype;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5920
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5921 if (*op == '.')
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5922 expected = &t_string;
21881
675bf9475fff patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
5923 else
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
5924 expected = member_type;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5925 stacktype = ((type_T **)stack->ga_data)[stack->ga_len - 1];
21881
675bf9475fff patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
5926 if (
675bf9475fff patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
5927 #ifdef FEAT_FLOAT
675bf9475fff patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
5928 // If variable is float operation with number is OK.
675bf9475fff patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
5929 !(expected == &t_float && stacktype == &t_number) &&
675bf9475fff patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
5930 #endif
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5931 need_type(stacktype, expected, -1, cctx,
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5932 FALSE, FALSE) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5933 goto theend;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5934
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5935 if (*op == '.')
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
5936 {
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
5937 if (generate_instr_drop(cctx, ISN_CONCAT, 1) == NULL)
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
5938 goto theend;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
5939 }
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
5940 else if (*op == '+')
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
5941 {
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
5942 if (generate_add_instr(cctx,
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
5943 operator_type(member_type, stacktype),
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
5944 member_type, stacktype) == FAIL)
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
5945 goto theend;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
5946 }
21881
675bf9475fff patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
5947 else if (generate_two_op(cctx, op) == FAIL)
675bf9475fff patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
5948 goto theend;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5949 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5950
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5951 if (has_index)
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5952 {
23245
ac934fbacc0e patch 8.2.2168: Vim9: error for assigning to dict of dict
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
5953 int r;
ac934fbacc0e patch 8.2.2168: Vim9: error for assigning to dict of dict
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
5954 vartype_T dest_type;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5955
22906
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5956 // Compile the "idx" in "var[idx]" or "key" in "var.key".
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5957 p = var_start + varlen;
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5958 if (*p == '[')
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5959 {
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5960 p = skipwhite(p + 1);
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5961 r = compile_expr0(&p, cctx);
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5962 if (r == OK && *skipwhite(p) != ']')
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5963 {
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5964 // this should not happen
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5965 emsg(_(e_missbrac));
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5966 r = FAIL;
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5967 }
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5968 }
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5969 else // if (*p == '.')
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5970 {
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5971 char_u *key_end = to_name_end(p + 1, TRUE);
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5972 char_u *key = vim_strnsave(p + 1, key_end - p - 1);
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5973
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5974 r = generate_PUSHS(cctx, key);
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5975 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5976 if (r == FAIL)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5977 goto theend;
22906
5ff7125e81fc patch 8.2.2000: Vim9: dict.key assignment not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 22898
diff changeset
5978
21578
7417cb54cb24 patch 8.2.1339: Vim9: assigning to global dict variable doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
5979 if (type == &t_any)
7417cb54cb24 patch 8.2.1339: Vim9: assigning to global dict variable doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
5980 {
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
5981 // Index on variable of unknown type: check at runtime.
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
5982 dest_type = VAR_ANY;
21578
7417cb54cb24 patch 8.2.1339: Vim9: assigning to global dict variable doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
5983 }
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
5984 else
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
5985 {
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
5986 dest_type = type->tt_type;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
5987 if (dest_type == VAR_DICT
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
5988 && may_generate_2STRING(-1, cctx) == FAIL)
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
5989 goto theend;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
5990 if (dest_type == VAR_LIST
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
5991 && ((type_T **)stack->ga_data)[stack->ga_len - 1]->tt_type
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5992 != VAR_NUMBER)
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
5993 {
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
5994 emsg(_(e_number_exp));
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
5995 goto theend;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
5996 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5997 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5998
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
5999 // Load the dict or list. On the stack we then have:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6000 // - value
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6001 // - index
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6002 // - variable
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6003 if (dest == dest_expr)
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6004 {
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6005 int c = var_start[varlen];
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6006
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6007 // Evaluate "ll[expr]" of "ll[expr][idx]"
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6008 p = var_start;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6009 var_start[varlen] = NUL;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6010 if (compile_expr0(&p, cctx) == OK && p != var_start + varlen)
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6011 {
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6012 // this should not happen
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6013 emsg(_(e_missbrac));
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6014 goto theend;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6015 }
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6016 var_start[varlen] = c;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6017
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6018 type = stack->ga_len == 0 ? &t_void
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6019 : ((type_T **)stack->ga_data)[stack->ga_len - 1];
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6020 // now we can properly check the type
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6021 if (type->tt_member != NULL
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6022 && need_type(rhs_type, type->tt_member, -2, cctx,
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6023 FALSE, FALSE) == FAIL)
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6024 goto theend;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6025 }
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6026 else
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6027 generate_loadvar(cctx, dest, name, lvar, type);
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6028
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
6029 if (dest_type == VAR_LIST || dest_type == VAR_DICT
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
6030 || dest_type == VAR_ANY)
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6031 {
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
6032 isn_T *isn = generate_instr_drop(cctx, ISN_STOREINDEX, 3);
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
6033
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
6034 if (isn == NULL)
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6035 goto theend;
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
6036 isn->isn_arg.vartype = dest_type;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6037 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6038 else
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6039 {
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6040 emsg(_(e_indexable_type_required));
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6041 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6042 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6043 }
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6044 else
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6045 {
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6046 if (is_decl && cmdidx == CMD_const
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6047 && (dest == dest_script || dest == dest_local))
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6048 // ":const var": lock the value, but not referenced variables
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
6049 generate_LOCKCONST(cctx);
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
6050
23458
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
6051 if (is_decl
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
6052 && (type->tt_type == VAR_DICT || type->tt_type == VAR_LIST)
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
6053 && type->tt_member != NULL
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
6054 && type->tt_member != &t_any
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
6055 && type->tt_member != &t_unknown)
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
6056 // Set the type in the list or dict, so that it can be checked,
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
6057 // also in legacy script.
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
6058 generate_SETTYPE(cctx, type);
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
6059
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6060 if (dest != dest_local)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6061 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6062 if (generate_store_var(cctx, dest, opt_flags, vimvaridx,
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6063 scriptvar_idx, scriptvar_sid, type, name) == FAIL)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6064 goto theend;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6065 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6066 else if (lvar != NULL)
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6067 {
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6068 isn_T *isn = ((isn_T *)instr->ga_data)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6069 + instr->ga_len - 1;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6070
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6071 // optimization: turn "var = 123" from ISN_PUSHNR +
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6072 // ISN_STORE into ISN_STORENR
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6073 if (!lvar->lv_from_outer
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6074 && instr->ga_len == instr_count + 1
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6075 && isn->isn_type == ISN_PUSHNR)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6076 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6077 varnumber_T val = isn->isn_arg.number;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6078
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6079 isn->isn_type = ISN_STORENR;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6080 isn->isn_arg.storenr.stnr_idx = lvar->lv_idx;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6081 isn->isn_arg.storenr.stnr_val = val;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6082 if (stack->ga_len > 0)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6083 --stack->ga_len;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6084 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6085 else if (lvar->lv_from_outer)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6086 generate_STORE(cctx, ISN_STOREOUTER, lvar->lv_idx, NULL);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6087 else
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6088 generate_STORE(cctx, ISN_STORE, lvar->lv_idx, NULL);
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6089 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6090 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6091
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6092 if (var_idx + 1 < var_count)
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6093 var_start = skipwhite(dest_end + 1);
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6094 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6095
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6096 // for "[var, var] = expr" drop the "expr" value
20871
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
6097 if (var_count > 0 && !semicolon)
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
6098 {
23195
75f35ae990ac patch 8.2.2143: Vim9: dead code in compiling :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23187
diff changeset
6099 if (generate_instr_drop(cctx, ISN_DROP, 1) == NULL)
20871
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
6100 goto theend;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
6101 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6102
21391
8b882afa8ed2 patch 8.2.1246: Vim9: comment after assignment doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21387
diff changeset
6103 ret = skipwhite(end);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6104
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6105 theend:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6106 vim_free(name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6107 return ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6108 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6109
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6110 /*
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6111 * Check if "name" can be "unlet".
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6112 */
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6113 int
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6114 check_vim9_unlet(char_u *name)
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6115 {
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6116 if (name[1] != ':' || vim_strchr((char_u *)"gwtb", *name) == NULL)
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6117 {
21931
8e09827f8bac patch 8.2.1515: Vim9: can create s:var in legacy script but cannot unlet
Bram Moolenaar <Bram@vim.org>
parents: 21921
diff changeset
6118 // "unlet s:var" is allowed in legacy script.
8e09827f8bac patch 8.2.1515: Vim9: can create s:var in legacy script but cannot unlet
Bram Moolenaar <Bram@vim.org>
parents: 21921
diff changeset
6119 if (*name == 's' && !script_is_vim9())
8e09827f8bac patch 8.2.1515: Vim9: can create s:var in legacy script but cannot unlet
Bram Moolenaar <Bram@vim.org>
parents: 21921
diff changeset
6120 return OK;
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
6121 semsg(_(e_cannot_unlet_str), name);
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6122 return FAIL;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6123 }
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6124 return OK;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6125 }
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6126
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6127 /*
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6128 * Callback passed to ex_unletlock().
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6129 */
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6130 static int
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6131 compile_unlet(
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6132 lval_T *lvp,
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6133 char_u *name_end,
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6134 exarg_T *eap,
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6135 int deep UNUSED,
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6136 void *coookie)
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6137 {
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6138 cctx_T *cctx = coookie;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6139
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6140 if (lvp->ll_tv == NULL)
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6141 {
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6142 char_u *p = lvp->ll_name;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6143 int cc = *name_end;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6144 int ret = OK;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6145
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6146 // Normal name. Only supports g:, w:, t: and b: namespaces.
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6147 *name_end = NUL;
23495
1f85acfb23cd patch 8.2.2290: Vim9: unlet of global variable cannot be compiled
Bram Moolenaar <Bram@vim.org>
parents: 23491
diff changeset
6148 if (vim_strchr(p, '.') != NULL || vim_strchr(p, '[') != NULL)
1f85acfb23cd patch 8.2.2290: Vim9: unlet of global variable cannot be compiled
Bram Moolenaar <Bram@vim.org>
parents: 23491
diff changeset
6149 {
1f85acfb23cd patch 8.2.2290: Vim9: unlet of global variable cannot be compiled
Bram Moolenaar <Bram@vim.org>
parents: 23491
diff changeset
6150 *name_end = cc;
1f85acfb23cd patch 8.2.2290: Vim9: unlet of global variable cannot be compiled
Bram Moolenaar <Bram@vim.org>
parents: 23491
diff changeset
6151 goto failed;
1f85acfb23cd patch 8.2.2290: Vim9: unlet of global variable cannot be compiled
Bram Moolenaar <Bram@vim.org>
parents: 23491
diff changeset
6152 }
1f85acfb23cd patch 8.2.2290: Vim9: unlet of global variable cannot be compiled
Bram Moolenaar <Bram@vim.org>
parents: 23491
diff changeset
6153
20099
058b41f85bcb patch 8.2.0605: Vim9: cannot unlet an environment variable
Bram Moolenaar <Bram@vim.org>
parents: 20091
diff changeset
6154 if (*p == '$')
058b41f85bcb patch 8.2.0605: Vim9: cannot unlet an environment variable
Bram Moolenaar <Bram@vim.org>
parents: 20091
diff changeset
6155 ret = generate_UNLET(cctx, ISN_UNLETENV, p + 1, eap->forceit);
058b41f85bcb patch 8.2.0605: Vim9: cannot unlet an environment variable
Bram Moolenaar <Bram@vim.org>
parents: 20091
diff changeset
6156 else if (check_vim9_unlet(p) == FAIL)
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6157 ret = FAIL;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6158 else
20099
058b41f85bcb patch 8.2.0605: Vim9: cannot unlet an environment variable
Bram Moolenaar <Bram@vim.org>
parents: 20091
diff changeset
6159 ret = generate_UNLET(cctx, ISN_UNLET, p, eap->forceit);
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6160
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6161 *name_end = cc;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6162 return ret;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6163 }
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6164
23495
1f85acfb23cd patch 8.2.2290: Vim9: unlet of global variable cannot be compiled
Bram Moolenaar <Bram@vim.org>
parents: 23491
diff changeset
6165 failed:
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6166 // TODO: unlet {list}[idx]
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6167 // TODO: unlet {dict}[key]
23495
1f85acfb23cd patch 8.2.2290: Vim9: unlet of global variable cannot be compiled
Bram Moolenaar <Bram@vim.org>
parents: 23491
diff changeset
6168 // complication: {list} can be global while "idx" is local, thus we can't
1f85acfb23cd patch 8.2.2290: Vim9: unlet of global variable cannot be compiled
Bram Moolenaar <Bram@vim.org>
parents: 23491
diff changeset
6169 // call ex_unlet().
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6170 emsg("Sorry, :unlet not fully implemented yet");
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6171 return FAIL;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6172 }
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6173
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6174 /*
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6175 * compile "unlet var", "lock var" and "unlock var"
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6176 * "arg" points to "var".
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6177 */
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6178 static char_u *
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6179 compile_unletlock(char_u *arg, exarg_T *eap, cctx_T *cctx)
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6180 {
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6181 char_u *p = arg;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6182
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6183 if (eap->cmdidx != CMD_unlet)
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6184 {
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6185 emsg("Sorry, :lock and unlock not implemented yet");
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6186 return NULL;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6187 }
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6188
23450
a8e7acf71fa4 patch 8.2.2268: Vim9: list unpack seen as declaration
Bram Moolenaar <Bram@vim.org>
parents: 23446
diff changeset
6189 // TODO: this doesn't work for local variables
23495
1f85acfb23cd patch 8.2.2290: Vim9: unlet of global variable cannot be compiled
Bram Moolenaar <Bram@vim.org>
parents: 23491
diff changeset
6190 ex_unletlock(eap, p, 0, GLV_NO_AUTOLOAD | GLV_COMPILING,
1f85acfb23cd patch 8.2.2290: Vim9: unlet of global variable cannot be compiled
Bram Moolenaar <Bram@vim.org>
parents: 23491
diff changeset
6191 compile_unlet, cctx);
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6192 return eap->nextcmd == NULL ? (char_u *)"" : eap->nextcmd;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6193 }
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6194
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6195 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6196 * Compile an :import command.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6197 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6198 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6199 compile_import(char_u *arg, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6200 {
21146
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
6201 return handle_import(arg, &cctx->ctx_imports, 0, NULL, cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6202 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6203
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6204 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6205 * generate a jump to the ":endif"/":endfor"/":endwhile"/":finally"/":endtry".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6206 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6207 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6208 compile_jump_to_end(endlabel_T **el, jumpwhen_T when, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6209 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6210 garray_T *instr = &cctx->ctx_instr;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6211 endlabel_T *endlabel = ALLOC_CLEAR_ONE(endlabel_T);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6212
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6213 if (endlabel == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6214 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6215 endlabel->el_next = *el;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6216 *el = endlabel;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6217 endlabel->el_end_label = instr->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6218
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6219 generate_JUMP(cctx, when, 0);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6220 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6221 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6222
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6223 static void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6224 compile_fill_jump_to_end(endlabel_T **el, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6225 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6226 garray_T *instr = &cctx->ctx_instr;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6227
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6228 while (*el != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6229 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6230 endlabel_T *cur = (*el);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6231 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6232
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6233 isn = ((isn_T *)instr->ga_data) + cur->el_end_label;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6234 isn->isn_arg.jump.jump_where = instr->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6235 *el = cur->el_next;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6236 vim_free(cur);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6237 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6238 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6239
19896
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6240 static void
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6241 compile_free_jump_to_end(endlabel_T **el)
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6242 {
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6243 while (*el != NULL)
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6244 {
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6245 endlabel_T *cur = (*el);
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6246
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6247 *el = cur->el_next;
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6248 vim_free(cur);
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6249 }
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6250 }
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6251
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6252 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6253 * Create a new scope and set up the generic items.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6254 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6255 static scope_T *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6256 new_scope(cctx_T *cctx, scopetype_T type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6257 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6258 scope_T *scope = ALLOC_CLEAR_ONE(scope_T);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6259
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6260 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6261 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6262 scope->se_outer = cctx->ctx_scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6263 cctx->ctx_scope = scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6264 scope->se_type = type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6265 scope->se_local_count = cctx->ctx_locals.ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6266 return scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6267 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6268
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6269 /*
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6270 * Free the current scope and go back to the outer scope.
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6271 */
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6272 static void
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6273 drop_scope(cctx_T *cctx)
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6274 {
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6275 scope_T *scope = cctx->ctx_scope;
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6276
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6277 if (scope == NULL)
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6278 {
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6279 iemsg("calling drop_scope() without a scope");
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6280 return;
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6281 }
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6282 cctx->ctx_scope = scope->se_outer;
19896
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6283 switch (scope->se_type)
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6284 {
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6285 case IF_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6286 compile_free_jump_to_end(&scope->se_u.se_if.is_end_label); break;
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6287 case FOR_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6288 compile_free_jump_to_end(&scope->se_u.se_for.fs_end_label); break;
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6289 case WHILE_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6290 compile_free_jump_to_end(&scope->se_u.se_while.ws_end_label); break;
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6291 case TRY_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6292 compile_free_jump_to_end(&scope->se_u.se_try.ts_end_label); break;
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6293 case NO_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6294 case BLOCK_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6295 break;
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
6296 }
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6297 vim_free(scope);
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6298 }
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6299
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6300 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6301 * compile "if expr"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6302 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6303 * "if expr" Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6304 * EVAL expr Push result of "expr"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6305 * JUMP_IF_FALSE end
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6306 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6307 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6308 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6309 * "if expr | else" Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6310 * EVAL expr Push result of "expr"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6311 * JUMP_IF_FALSE else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6312 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6313 * JUMP_ALWAYS end
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6314 * else:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6315 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6316 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6317 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6318 * "if expr1 | elseif expr2 | else" Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6319 * EVAL expr Push result of "expr"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6320 * JUMP_IF_FALSE elseif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6321 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6322 * JUMP_ALWAYS end
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6323 * elseif:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6324 * EVAL expr Push result of "expr"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6325 * JUMP_IF_FALSE else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6326 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6327 * JUMP_ALWAYS end
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6328 * else:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6329 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6330 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6331 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6332 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6333 compile_if(char_u *arg, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6334 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6335 char_u *p = arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6336 garray_T *instr = &cctx->ctx_instr;
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
6337 int instr_count = instr->ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6338 scope_T *scope;
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6339 skip_T skip_save = cctx->ctx_skip;
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
6340 ppconst_T ppconst;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
6341
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
6342 CLEAR_FIELD(ppconst);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
6343 if (compile_expr1(&p, cctx, &ppconst) == FAIL)
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
6344 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
6345 clear_ppconst(&ppconst);
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
6346 return NULL;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
6347 }
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6348 if (cctx->ctx_skip == SKIP_YES)
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6349 clear_ppconst(&ppconst);
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6350 else if (instr->ga_len == instr_count && ppconst.pp_used == 1)
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
6351 {
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
6352 int error = FALSE;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
6353 int v;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
6354
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
6355 // The expression results in a constant.
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
6356 v = tv_get_bool_chk(&ppconst.pp_tv[0], &error);
22504
47e15b82dba1 patch 8.2.1800: Vim9: memory leak if "if" condition is invalid
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
6357 clear_ppconst(&ppconst);
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
6358 if (error)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
6359 return NULL;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
6360 cctx->ctx_skip = v ? SKIP_NOT : SKIP_YES;
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
6361 }
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6362 else
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
6363 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
6364 // Not a constant, generate instructions for the expression.
20933
e2fd5f05342f patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents: 20929
diff changeset
6365 cctx->ctx_skip = SKIP_UNKNOWN;
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
6366 if (generate_ppconst(cctx, &ppconst) == FAIL)
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6367 return NULL;
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
6368 if (bool_on_stack(cctx) == FAIL)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
6369 return NULL;
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6370 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6371
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6372 scope = new_scope(cctx, IF_SCOPE);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6373 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6374 return NULL;
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6375 scope->se_skip_save = skip_save;
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6376 // "is_had_return" will be reset if any block does not end in :return
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6377 scope->se_u.se_if.is_had_return = TRUE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6378
20933
e2fd5f05342f patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents: 20929
diff changeset
6379 if (cctx->ctx_skip == SKIP_UNKNOWN)
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6380 {
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6381 // "where" is set when ":elseif", "else" or ":endif" is found
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6382 scope->se_u.se_if.is_if_label = instr->ga_len;
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6383 generate_JUMP(cctx, JUMP_IF_FALSE, 0);
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6384 }
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6385 else
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6386 scope->se_u.se_if.is_if_label = -1;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6387
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6388 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6389 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6390
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6391 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6392 compile_elseif(char_u *arg, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6393 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6394 char_u *p = arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6395 garray_T *instr = &cctx->ctx_instr;
20334
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
6396 int instr_count = instr->ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6397 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6398 scope_T *scope = cctx->ctx_scope;
20334
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
6399 ppconst_T ppconst;
21959
67d4be2757b0 patch 8.2.1529: Vim9: :elseif may be compiled when not needed
Bram Moolenaar <Bram@vim.org>
parents: 21957
diff changeset
6400 skip_T save_skip = cctx->ctx_skip;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6401
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6402 if (scope == NULL || scope->se_type != IF_SCOPE)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6403 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6404 emsg(_(e_elseif_without_if));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6405 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6406 }
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
6407 unwind_locals(cctx, scope->se_local_count);
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6408 if (!cctx->ctx_had_return)
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6409 scope->se_u.se_if.is_had_return = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6410
20933
e2fd5f05342f patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents: 20929
diff changeset
6411 if (cctx->ctx_skip == SKIP_UNKNOWN)
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6412 {
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6413 if (compile_jump_to_end(&scope->se_u.se_if.is_end_label,
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6414 JUMP_ALWAYS, cctx) == FAIL)
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6415 return NULL;
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6416 // previous "if" or "elseif" jumps here
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6417 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_if.is_if_label;
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6418 isn->isn_arg.jump.jump_where = instr->ga_len;
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6419 }
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6420
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6421 // compile "expr"; if we know it evaluates to FALSE skip the block
20334
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
6422 CLEAR_FIELD(ppconst);
21959
67d4be2757b0 patch 8.2.1529: Vim9: :elseif may be compiled when not needed
Bram Moolenaar <Bram@vim.org>
parents: 21957
diff changeset
6423 if (cctx->ctx_skip == SKIP_YES)
67d4be2757b0 patch 8.2.1529: Vim9: :elseif may be compiled when not needed
Bram Moolenaar <Bram@vim.org>
parents: 21957
diff changeset
6424 cctx->ctx_skip = SKIP_UNKNOWN;
20334
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
6425 if (compile_expr1(&p, cctx, &ppconst) == FAIL)
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
6426 {
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
6427 clear_ppconst(&ppconst);
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
6428 return NULL;
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
6429 }
21959
67d4be2757b0 patch 8.2.1529: Vim9: :elseif may be compiled when not needed
Bram Moolenaar <Bram@vim.org>
parents: 21957
diff changeset
6430 cctx->ctx_skip = save_skip;
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6431 if (scope->se_skip_save == SKIP_YES)
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6432 clear_ppconst(&ppconst);
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6433 else if (instr->ga_len == instr_count && ppconst.pp_used == 1)
20334
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
6434 {
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
6435 int error = FALSE;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
6436 int v;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
6437
20334
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
6438 // The expression results in a constant.
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
6439 // TODO: how about nesting?
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
6440 v = tv_get_bool_chk(&ppconst.pp_tv[0], &error);
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
6441 if (error)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
6442 return NULL;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
6443 cctx->ctx_skip = v ? SKIP_NOT : SKIP_YES;
20334
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
6444 clear_ppconst(&ppconst);
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
6445 scope->se_u.se_if.is_if_label = -1;
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
6446 }
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6447 else
20334
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
6448 {
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
6449 // Not a constant, generate instructions for the expression.
20933
e2fd5f05342f patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents: 20929
diff changeset
6450 cctx->ctx_skip = SKIP_UNKNOWN;
20334
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
6451 if (generate_ppconst(cctx, &ppconst) == FAIL)
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6452 return NULL;
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
6453 if (bool_on_stack(cctx) == FAIL)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
6454 return NULL;
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6455
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6456 // "where" is set when ":elseif", "else" or ":endif" is found
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6457 scope->se_u.se_if.is_if_label = instr->ga_len;
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6458 generate_JUMP(cctx, JUMP_IF_FALSE, 0);
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6459 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6460
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6461 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6462 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6463
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6464 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6465 compile_else(char_u *arg, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6466 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6467 char_u *p = arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6468 garray_T *instr = &cctx->ctx_instr;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6469 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6470 scope_T *scope = cctx->ctx_scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6471
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6472 if (scope == NULL || scope->se_type != IF_SCOPE)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6473 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6474 emsg(_(e_else_without_if));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6475 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6476 }
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
6477 unwind_locals(cctx, scope->se_local_count);
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6478 if (!cctx->ctx_had_return)
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6479 scope->se_u.se_if.is_had_return = FALSE;
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6480 scope->se_u.se_if.is_seen_else = TRUE;
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6481
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6482 if (scope->se_skip_save != SKIP_YES)
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6483 {
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6484 // jump from previous block to the end, unless the else block is empty
20933
e2fd5f05342f patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents: 20929
diff changeset
6485 if (cctx->ctx_skip == SKIP_UNKNOWN)
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6486 {
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6487 if (!cctx->ctx_had_return
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6488 && compile_jump_to_end(&scope->se_u.se_if.is_end_label,
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6489 JUMP_ALWAYS, cctx) == FAIL)
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6490 return NULL;
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6491 }
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6492
20933
e2fd5f05342f patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents: 20929
diff changeset
6493 if (cctx->ctx_skip == SKIP_UNKNOWN)
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6494 {
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6495 if (scope->se_u.se_if.is_if_label >= 0)
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6496 {
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6497 // previous "if" or "elseif" jumps here
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6498 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_if.is_if_label;
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6499 isn->isn_arg.jump.jump_where = instr->ga_len;
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6500 scope->se_u.se_if.is_if_label = -1;
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6501 }
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6502 }
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6503
20933
e2fd5f05342f patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents: 20929
diff changeset
6504 if (cctx->ctx_skip != SKIP_UNKNOWN)
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6505 cctx->ctx_skip = cctx->ctx_skip == SKIP_YES ? SKIP_NOT : SKIP_YES;
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6506 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6507
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6508 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6509 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6510
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6511 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6512 compile_endif(char_u *arg, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6513 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6514 scope_T *scope = cctx->ctx_scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6515 ifscope_T *ifscope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6516 garray_T *instr = &cctx->ctx_instr;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6517 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6518
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6519 if (scope == NULL || scope->se_type != IF_SCOPE)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6520 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6521 emsg(_(e_endif_without_if));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6522 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6523 }
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
6524 ifscope = &scope->se_u.se_if;
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
6525 unwind_locals(cctx, scope->se_local_count);
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6526 if (!cctx->ctx_had_return)
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6527 ifscope->is_had_return = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6528
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6529 if (scope->se_u.se_if.is_if_label >= 0)
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6530 {
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6531 // previous "if" or "elseif" jumps here
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6532 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_if.is_if_label;
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6533 isn->isn_arg.jump.jump_where = instr->ga_len;
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
6534 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6535 // Fill in the "end" label in jumps at the end of the blocks.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6536 compile_fill_jump_to_end(&ifscope->is_end_label, cctx);
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6537 cctx->ctx_skip = scope->se_skip_save;
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6538
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6539 // If all the blocks end in :return and there is an :else then the
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6540 // had_return flag is set.
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
6541 cctx->ctx_had_return = ifscope->is_had_return && ifscope->is_seen_else;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6542
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6543 drop_scope(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6544 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6545 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6546
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6547 /*
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6548 * Compile "for var in expr":
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6549 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6550 * Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6551 * PUSHNR -1
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6552 * STORE loop-idx Set index to -1
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6553 * EVAL expr result of "expr" on top of stack
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6554 * top: FOR loop-idx, end Increment index, use list on bottom of stack
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6555 * - if beyond end, jump to "end"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6556 * - otherwise get item from list and push it
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6557 * STORE var Store item in "var"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6558 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6559 * JUMP top Jump back to repeat
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6560 * end: DROP Drop the result of "expr"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6561 *
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6562 * Compile "for [var1, var2] in expr" - as above, but instead of "STORE var":
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6563 * UNPACK 2 Split item in 2
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6564 * STORE var1 Store item in "var1"
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6565 * STORE var2 Store item in "var2"
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6566 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6567 static char_u *
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6568 compile_for(char_u *arg_start, cctx_T *cctx)
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6569 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6570 char_u *arg;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6571 char_u *arg_end;
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6572 char_u *name = NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6573 char_u *p;
23066
b3124656f050 patch 8.2.2079: Vim9: cannot put a linebreak before or after "in" of ":for"
Bram Moolenaar <Bram@vim.org>
parents: 23054
diff changeset
6574 char_u *wp;
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6575 int var_count = 0;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6576 int semicolon = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6577 size_t varlen;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6578 garray_T *instr = &cctx->ctx_instr;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6579 garray_T *stack = &cctx->ctx_type_stack;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6580 scope_T *scope;
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
6581 lvar_T *loop_lvar; // loop iteration variable
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
6582 lvar_T *var_lvar; // variable for "var"
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6583 type_T *vartype;
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6584 type_T *item_type = &t_any;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6585 int idx;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6586
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6587 p = skip_var_list(arg_start, TRUE, &var_count, &semicolon, FALSE);
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6588 if (var_count == 0)
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6589 var_count = 1;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6590
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6591 // consume "in"
23066
b3124656f050 patch 8.2.2079: Vim9: cannot put a linebreak before or after "in" of ":for"
Bram Moolenaar <Bram@vim.org>
parents: 23054
diff changeset
6592 wp = p;
b3124656f050 patch 8.2.2079: Vim9: cannot put a linebreak before or after "in" of ":for"
Bram Moolenaar <Bram@vim.org>
parents: 23054
diff changeset
6593 if (may_get_next_line_error(wp, &p, cctx) == FAIL)
b3124656f050 patch 8.2.2079: Vim9: cannot put a linebreak before or after "in" of ":for"
Bram Moolenaar <Bram@vim.org>
parents: 23054
diff changeset
6594 return NULL;
b3124656f050 patch 8.2.2079: Vim9: cannot put a linebreak before or after "in" of ":for"
Bram Moolenaar <Bram@vim.org>
parents: 23054
diff changeset
6595 if (STRNCMP(p, "in", 2) != 0 || !IS_WHITE_OR_NUL(p[2]))
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6596 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6597 emsg(_(e_missing_in));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6598 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6599 }
23066
b3124656f050 patch 8.2.2079: Vim9: cannot put a linebreak before or after "in" of ":for"
Bram Moolenaar <Bram@vim.org>
parents: 23054
diff changeset
6600 wp = p + 2;
b3124656f050 patch 8.2.2079: Vim9: cannot put a linebreak before or after "in" of ":for"
Bram Moolenaar <Bram@vim.org>
parents: 23054
diff changeset
6601 if (may_get_next_line_error(wp, &p, cctx) == FAIL)
b3124656f050 patch 8.2.2079: Vim9: cannot put a linebreak before or after "in" of ":for"
Bram Moolenaar <Bram@vim.org>
parents: 23054
diff changeset
6602 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6603
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6604 scope = new_scope(cctx, FOR_SCOPE);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6605 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6606 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6607
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6608 // Reserve a variable to store the loop iteration counter and initialize it
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6609 // to -1.
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
6610 loop_lvar = reserve_local(cctx, (char_u *)"", 0, FALSE, &t_number);
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
6611 if (loop_lvar == NULL)
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
6612 {
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
6613 // out of memory
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6614 drop_scope(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6615 return NULL;
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6616 }
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
6617 generate_STORENR(cctx, loop_lvar->lv_idx, -1);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6618
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6619 // compile "expr", it remains on the stack until "endfor"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6620 arg = p;
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
6621 if (compile_expr0(&arg, cctx) == FAIL)
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6622 {
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6623 drop_scope(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6624 return NULL;
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6625 }
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6626 arg_end = arg;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6627
21188
d73b6ba20053 patch 8.2.1145: Vim9: "for" only accepts a list at compile time
Bram Moolenaar <Bram@vim.org>
parents: 21172
diff changeset
6628 // Now that we know the type of "var", check that it is a list, now or at
d73b6ba20053 patch 8.2.1145: Vim9: "for" only accepts a list at compile time
Bram Moolenaar <Bram@vim.org>
parents: 21172
diff changeset
6629 // runtime.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6630 vartype = ((type_T **)stack->ga_data)[stack->ga_len - 1];
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
6631 if (need_type(vartype, &t_list_any, -1, cctx, FALSE, FALSE) == FAIL)
21188
d73b6ba20053 patch 8.2.1145: Vim9: "for" only accepts a list at compile time
Bram Moolenaar <Bram@vim.org>
parents: 21172
diff changeset
6632 {
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
6633 drop_scope(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6634 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6635 }
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6636
21188
d73b6ba20053 patch 8.2.1145: Vim9: "for" only accepts a list at compile time
Bram Moolenaar <Bram@vim.org>
parents: 21172
diff changeset
6637 if (vartype->tt_type == VAR_LIST && vartype->tt_member->tt_type != VAR_ANY)
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6638 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6639 if (var_count == 1)
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6640 item_type = vartype->tt_member;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6641 else if (vartype->tt_member->tt_type == VAR_LIST
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6642 && vartype->tt_member->tt_member->tt_type != VAR_ANY)
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6643 item_type = vartype->tt_member->tt_member;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6644 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6645
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6646 // "for_end" is set when ":endfor" is found
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
6647 scope->se_u.se_for.fs_top_label = instr->ga_len;
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
6648 generate_FOR(cctx, loop_lvar->lv_idx);
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6649
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6650 arg = arg_start;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6651 if (var_count > 1)
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6652 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6653 generate_UNPACK(cctx, var_count, semicolon);
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6654 arg = skipwhite(arg + 1); // skip white after '['
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6655
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6656 // the list item is replaced by a number of items
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6657 if (ga_grow(stack, var_count - 1) == FAIL)
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6658 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6659 drop_scope(cctx);
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6660 return NULL;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6661 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6662 --stack->ga_len;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6663 for (idx = 0; idx < var_count; ++idx)
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6664 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6665 ((type_T **)stack->ga_data)[stack->ga_len] =
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6666 (semicolon && idx == 0) ? vartype : item_type;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6667 ++stack->ga_len;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6668 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6669 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6670
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6671 for (idx = 0; idx < var_count; ++idx)
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6672 {
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6673 assign_dest_T dest = dest_local;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6674 int opt_flags = 0;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6675 int vimvaridx = -1;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6676 type_T *type = &t_any;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6677
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6678 p = skip_var_one(arg, FALSE);
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6679 varlen = p - arg;
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6680 name = vim_strnsave(arg, varlen);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6681 if (name == NULL)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6682 goto failed;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6683
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6684 // TODO: script var not supported?
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6685 if (get_var_dest(name, &dest, CMD_for, &opt_flags,
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6686 &vimvaridx, &type, cctx) == FAIL)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6687 goto failed;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6688 if (dest != dest_local)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6689 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6690 if (generate_store_var(cctx, dest, opt_flags, vimvaridx,
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6691 0, 0, type, name) == FAIL)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6692 goto failed;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6693 }
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6694 else
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6695 {
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
6696 if (lookup_local(arg, varlen, NULL, cctx) == OK)
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6697 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6698 semsg(_(e_variable_already_declared), arg);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6699 goto failed;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6700 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6701
23068
2f034cb0a046 patch 8.2.2080: Vim9: no proper error message for using s:var in for loop
Bram Moolenaar <Bram@vim.org>
parents: 23066
diff changeset
6702 if (STRNCMP(name, "s:", 2) == 0)
2f034cb0a046 patch 8.2.2080: Vim9: no proper error message for using s:var in for loop
Bram Moolenaar <Bram@vim.org>
parents: 23066
diff changeset
6703 {
2f034cb0a046 patch 8.2.2080: Vim9: no proper error message for using s:var in for loop
Bram Moolenaar <Bram@vim.org>
parents: 23066
diff changeset
6704 semsg(_(e_cannot_declare_script_variable_in_function), name);
2f034cb0a046 patch 8.2.2080: Vim9: no proper error message for using s:var in for loop
Bram Moolenaar <Bram@vim.org>
parents: 23066
diff changeset
6705 goto failed;
2f034cb0a046 patch 8.2.2080: Vim9: no proper error message for using s:var in for loop
Bram Moolenaar <Bram@vim.org>
parents: 23066
diff changeset
6706 }
2f034cb0a046 patch 8.2.2080: Vim9: no proper error message for using s:var in for loop
Bram Moolenaar <Bram@vim.org>
parents: 23066
diff changeset
6707
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6708 // Reserve a variable to store "var".
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6709 // TODO: check for type
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6710 var_lvar = reserve_local(cctx, arg, varlen, FALSE, &t_any);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6711 if (var_lvar == NULL)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6712 // out of memory or used as an argument
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6713 goto failed;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6714
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6715 if (semicolon && idx == var_count - 1)
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6716 var_lvar->lv_type = vartype;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6717 else
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6718 var_lvar->lv_type = item_type;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6719 generate_STORE(cctx, ISN_STORE, var_lvar->lv_idx, NULL);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6720 }
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6721
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6722 if (*p == ',' || *p == ';')
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6723 ++p;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6724 arg = skipwhite(p);
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6725 vim_free(name);
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6726 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6727
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
6728 return arg_end;
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6729
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6730 failed:
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6731 vim_free(name);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6732 drop_scope(cctx);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6733 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6734 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6735
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6736 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6737 * compile "endfor"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6738 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6739 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6740 compile_endfor(char_u *arg, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6741 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6742 garray_T *instr = &cctx->ctx_instr;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6743 scope_T *scope = cctx->ctx_scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6744 forscope_T *forscope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6745 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6746
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6747 if (scope == NULL || scope->se_type != FOR_SCOPE)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6748 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6749 emsg(_(e_for));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6750 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6751 }
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
6752 forscope = &scope->se_u.se_for;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6753 cctx->ctx_scope = scope->se_outer;
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
6754 unwind_locals(cctx, scope->se_local_count);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6755
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6756 // At end of ":for" scope jump back to the FOR instruction.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6757 generate_JUMP(cctx, JUMP_ALWAYS, forscope->fs_top_label);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6758
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6759 // Fill in the "end" label in the FOR statement so it can jump here
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6760 isn = ((isn_T *)instr->ga_data) + forscope->fs_top_label;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6761 isn->isn_arg.forloop.for_end = instr->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6762
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6763 // Fill in the "end" label any BREAK statements
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6764 compile_fill_jump_to_end(&forscope->fs_end_label, cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6765
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6766 // Below the ":for" scope drop the "expr" list from the stack.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6767 if (generate_instr_drop(cctx, ISN_DROP, 1) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6768 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6769
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6770 vim_free(scope);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6771
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6772 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6773 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6774
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6775 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6776 * compile "while expr"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6777 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6778 * Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6779 * top: EVAL expr Push result of "expr"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6780 * JUMP_IF_FALSE end jump if false
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6781 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6782 * JUMP top Jump back to repeat
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6783 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6784 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6785 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6786 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6787 compile_while(char_u *arg, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6788 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6789 char_u *p = arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6790 garray_T *instr = &cctx->ctx_instr;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6791 scope_T *scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6792
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6793 scope = new_scope(cctx, WHILE_SCOPE);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6794 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6795 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6796
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
6797 scope->se_u.se_while.ws_top_label = instr->ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6798
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6799 // compile "expr"
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
6800 if (compile_expr0(&p, cctx) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6801 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6802
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
6803 if (bool_on_stack(cctx) == FAIL)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
6804 return FAIL;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
6805
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6806 // "while_end" is set when ":endwhile" is found
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
6807 if (compile_jump_to_end(&scope->se_u.se_while.ws_end_label,
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6808 JUMP_IF_FALSE, cctx) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6809 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6810
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6811 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6812 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6813
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6814 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6815 * compile "endwhile"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6816 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6817 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6818 compile_endwhile(char_u *arg, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6819 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6820 scope_T *scope = cctx->ctx_scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6821
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6822 if (scope == NULL || scope->se_type != WHILE_SCOPE)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6823 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6824 emsg(_(e_while));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6825 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6826 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6827 cctx->ctx_scope = scope->se_outer;
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
6828 unwind_locals(cctx, scope->se_local_count);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6829
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6830 // At end of ":for" scope jump back to the FOR instruction.
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
6831 generate_JUMP(cctx, JUMP_ALWAYS, scope->se_u.se_while.ws_top_label);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6832
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6833 // Fill in the "end" label in the WHILE statement so it can jump here.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6834 // And in any jumps for ":break"
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
6835 compile_fill_jump_to_end(&scope->se_u.se_while.ws_end_label, cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6836
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6837 vim_free(scope);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6838
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6839 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6840 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6841
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6842 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6843 * compile "continue"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6844 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6845 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6846 compile_continue(char_u *arg, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6847 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6848 scope_T *scope = cctx->ctx_scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6849
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6850 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6851 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6852 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6853 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6854 emsg(_(e_continue));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6855 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6856 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6857 if (scope->se_type == FOR_SCOPE || scope->se_type == WHILE_SCOPE)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6858 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6859 scope = scope->se_outer;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6860 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6861
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6862 // Jump back to the FOR or WHILE instruction.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6863 generate_JUMP(cctx, JUMP_ALWAYS,
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
6864 scope->se_type == FOR_SCOPE ? scope->se_u.se_for.fs_top_label
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
6865 : scope->se_u.se_while.ws_top_label);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6866 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6867 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6868
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6869 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6870 * compile "break"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6871 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6872 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6873 compile_break(char_u *arg, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6874 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6875 scope_T *scope = cctx->ctx_scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6876 endlabel_T **el;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6877
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6878 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6879 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6880 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6881 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6882 emsg(_(e_break));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6883 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6884 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6885 if (scope->se_type == FOR_SCOPE || scope->se_type == WHILE_SCOPE)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6886 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6887 scope = scope->se_outer;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6888 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6889
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6890 // Jump to the end of the FOR or WHILE loop.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6891 if (scope->se_type == FOR_SCOPE)
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
6892 el = &scope->se_u.se_for.fs_end_label;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6893 else
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
6894 el = &scope->se_u.se_while.ws_end_label;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6895 if (compile_jump_to_end(el, JUMP_ALWAYS, cctx) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6896 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6897
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6898 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6899 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6900
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6901 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6902 * compile "{" start of block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6903 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6904 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6905 compile_block(char_u *arg, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6906 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6907 if (new_scope(cctx, BLOCK_SCOPE) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6908 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6909 return skipwhite(arg + 1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6910 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6911
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6912 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6913 * compile end of block: drop one scope
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6914 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6915 static void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6916 compile_endblock(cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6917 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6918 scope_T *scope = cctx->ctx_scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6919
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6920 cctx->ctx_scope = scope->se_outer;
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
6921 unwind_locals(cctx, scope->se_local_count);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6922 vim_free(scope);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6923 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6924
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6925 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6926 * compile "try"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6927 * Creates a new scope for the try-endtry, pointing to the first catch and
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6928 * finally.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6929 * Creates another scope for the "try" block itself.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6930 * TRY instruction sets up exception handling at runtime.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6931 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6932 * "try"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6933 * TRY -> catch1, -> finally push trystack entry
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6934 * ... try block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6935 * "throw {exception}"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6936 * EVAL {exception}
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6937 * THROW create exception
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6938 * ... try block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6939 * " catch {expr}"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6940 * JUMP -> finally
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 23199
diff changeset
6941 * catch1: PUSH exception
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6942 * EVAL {expr}
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6943 * MATCH
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6944 * JUMP nomatch -> catch2
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6945 * CATCH remove exception
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6946 * ... catch block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6947 * " catch"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6948 * JUMP -> finally
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6949 * catch2: CATCH remove exception
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6950 * ... catch block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6951 * " finally"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6952 * finally:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6953 * ... finally block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6954 * " endtry"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6955 * ENDTRY pop trystack entry, may rethrow
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6956 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6957 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6958 compile_try(char_u *arg, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6959 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6960 garray_T *instr = &cctx->ctx_instr;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6961 scope_T *try_scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6962 scope_T *scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6963
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6964 // scope that holds the jumps that go to catch/finally/endtry
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6965 try_scope = new_scope(cctx, TRY_SCOPE);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6966 if (try_scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6967 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6968
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
6969 if (cctx->ctx_skip != SKIP_YES)
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
6970 {
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
6971 // "catch" is set when the first ":catch" is found.
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
6972 // "finally" is set when ":finally" or ":endtry" is found
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
6973 try_scope->se_u.se_try.ts_try_label = instr->ga_len;
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
6974 if (generate_instr(cctx, ISN_TRY) == NULL)
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
6975 return NULL;
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
6976 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6977
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6978 // scope for the try block itself
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6979 scope = new_scope(cctx, BLOCK_SCOPE);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6980 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6981 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6982
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6983 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6984 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6985
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6986 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6987 * compile "catch {expr}"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6988 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6989 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6990 compile_catch(char_u *arg, cctx_T *cctx UNUSED)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6991 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6992 scope_T *scope = cctx->ctx_scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6993 garray_T *instr = &cctx->ctx_instr;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6994 char_u *p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6995 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6996
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6997 // end block scope from :try or :catch
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6998 if (scope != NULL && scope->se_type == BLOCK_SCOPE)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6999 compile_endblock(cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7000 scope = cctx->ctx_scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7001
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7002 // Error if not in a :try scope
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7003 if (scope == NULL || scope->se_type != TRY_SCOPE)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7004 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7005 emsg(_(e_catch));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7006 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7007 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7008
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
7009 if (scope->se_u.se_try.ts_caught_all)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7010 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
7011 emsg(_(e_catch_unreachable_after_catch_all));
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7012 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7013 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7014
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7015 if (cctx->ctx_skip != SKIP_YES)
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7016 {
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7017 // Jump from end of previous block to :finally or :endtry
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7018 if (compile_jump_to_end(&scope->se_u.se_try.ts_end_label,
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7019 JUMP_ALWAYS, cctx) == FAIL)
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7020 return NULL;
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7021
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7022 // End :try or :catch scope: set value in ISN_TRY instruction
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7023 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_try_label;
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7024 if (isn->isn_arg.try.try_catch == 0)
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7025 isn->isn_arg.try.try_catch = instr->ga_len;
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7026 if (scope->se_u.se_try.ts_catch_label != 0)
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7027 {
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7028 // Previous catch without match jumps here
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7029 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_catch_label;
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7030 isn->isn_arg.jump.jump_where = instr->ga_len;
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7031 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7032 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7033
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7034 p = skipwhite(arg);
20059
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20055
diff changeset
7035 if (ends_excmd2(arg, p))
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7036 {
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
7037 scope->se_u.se_try.ts_caught_all = TRUE;
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
7038 scope->se_u.se_try.ts_catch_label = 0;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7039 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7040 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7041 {
19316
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
7042 char_u *end;
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
7043 char_u *pat;
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
7044 char_u *tofree = NULL;
19892
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19884
diff changeset
7045 int dropped = 0;
19388
3a579cadceb6 patch 8.2.0252: Windows compiler warns for using size_t
Bram Moolenaar <Bram@vim.org>
parents: 19342
diff changeset
7046 int len;
19316
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
7047
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7048 // Push v:exception, push {expr} and MATCH
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7049 generate_instr_type(cctx, ISN_PUSHEXC, &t_string);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7050
23505
bb29b09902d5 patch 8.2.2295: incsearch does not detect empty pattern properly
Bram Moolenaar <Bram@vim.org>
parents: 23497
diff changeset
7051 end = skip_regexp_ex(p + 1, *p, TRUE, &tofree, &dropped, NULL);
19316
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
7052 if (*end != *p)
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
7053 {
21909
a211bca98bc3 patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents: 21903
diff changeset
7054 semsg(_(e_separator_mismatch_str), p);
19316
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
7055 vim_free(tofree);
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
7056 return FAIL;
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
7057 }
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
7058 if (tofree == NULL)
19388
3a579cadceb6 patch 8.2.0252: Windows compiler warns for using size_t
Bram Moolenaar <Bram@vim.org>
parents: 19342
diff changeset
7059 len = (int)(end - (p + 1));
19316
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
7060 else
19892
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19884
diff changeset
7061 len = (int)(end - tofree);
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19884
diff changeset
7062 pat = vim_strnsave(tofree == NULL ? p + 1 : tofree, len);
19316
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
7063 vim_free(tofree);
19892
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19884
diff changeset
7064 p += len + 2 + dropped;
19316
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
7065 if (pat == NULL)
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
7066 return FAIL;
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
7067 if (generate_PUSHS(cctx, pat) == FAIL)
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
7068 return FAIL;
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
7069
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7070 if (generate_COMPARE(cctx, EXPR_MATCH, FALSE) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7071 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7072
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
7073 scope->se_u.se_try.ts_catch_label = instr->ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7074 if (generate_JUMP(cctx, JUMP_IF_FALSE, 0) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7075 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7076 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7077
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7078 if (cctx->ctx_skip != SKIP_YES && generate_instr(cctx, ISN_CATCH) == NULL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7079 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7080
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7081 if (new_scope(cctx, BLOCK_SCOPE) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7082 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7083 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7084 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7085
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7086 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7087 compile_finally(char_u *arg, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7088 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7089 scope_T *scope = cctx->ctx_scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7090 garray_T *instr = &cctx->ctx_instr;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7091 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7092
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7093 // end block scope from :try or :catch
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7094 if (scope != NULL && scope->se_type == BLOCK_SCOPE)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7095 compile_endblock(cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7096 scope = cctx->ctx_scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7097
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7098 // Error if not in a :try scope
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7099 if (scope == NULL || scope->se_type != TRY_SCOPE)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7100 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7101 emsg(_(e_finally));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7102 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7103 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7104
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7105 // End :catch or :finally scope: set value in ISN_TRY instruction
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
7106 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_try_label;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7107 if (isn->isn_arg.try.try_finally != 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7108 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7109 emsg(_(e_finally_dup));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7110 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7111 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7112
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7113 // Fill in the "end" label in jumps at the end of the blocks.
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
7114 compile_fill_jump_to_end(&scope->se_u.se_try.ts_end_label, cctx);
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
7115
19894
ea4f8e789627 patch 8.2.0503: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
7116 isn->isn_arg.try.try_finally = instr->ga_len;
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
7117 if (scope->se_u.se_try.ts_catch_label != 0)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7118 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7119 // Previous catch without match jumps here
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
7120 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_catch_label;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7121 isn->isn_arg.jump.jump_where = instr->ga_len;
21371
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21353
diff changeset
7122 scope->se_u.se_try.ts_catch_label = 0;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7123 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7124
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7125 // TODO: set index in ts_finally_label jumps
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7126
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7127 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7128 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7129
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7130 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7131 compile_endtry(char_u *arg, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7132 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7133 scope_T *scope = cctx->ctx_scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7134 garray_T *instr = &cctx->ctx_instr;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7135 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7136
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7137 // end block scope from :catch or :finally
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7138 if (scope != NULL && scope->se_type == BLOCK_SCOPE)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7139 compile_endblock(cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7140 scope = cctx->ctx_scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7141
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7142 // Error if not in a :try scope
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7143 if (scope == NULL || scope->se_type != TRY_SCOPE)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7144 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7145 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7146 emsg(_(e_no_endtry));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7147 else if (scope->se_type == WHILE_SCOPE)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7148 emsg(_(e_endwhile));
19213
b18437efabac patch 8.2.0165: Coverity warning for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents: 19193
diff changeset
7149 else if (scope->se_type == FOR_SCOPE)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7150 emsg(_(e_endfor));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7151 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7152 emsg(_(e_endif));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7153 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7154 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7155
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7156 if (cctx->ctx_skip != SKIP_YES)
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7157 {
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7158 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_try_label;
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7159 if (isn->isn_arg.try.try_catch == 0
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7160 && isn->isn_arg.try.try_finally == 0)
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7161 {
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7162 emsg(_(e_missing_catch_or_finally));
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7163 return NULL;
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7164 }
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7165
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7166 // Fill in the "end" label in jumps at the end of the blocks, if not
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7167 // done by ":finally".
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7168 compile_fill_jump_to_end(&scope->se_u.se_try.ts_end_label, cctx);
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7169
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7170 // End :catch or :finally scope: set value in ISN_TRY instruction
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7171 if (isn->isn_arg.try.try_catch == 0)
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7172 isn->isn_arg.try.try_catch = instr->ga_len;
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7173 if (isn->isn_arg.try.try_finally == 0)
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7174 isn->isn_arg.try.try_finally = instr->ga_len;
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7175
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7176 if (scope->se_u.se_try.ts_catch_label != 0)
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7177 {
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7178 // Last catch without match jumps here
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7179 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_catch_label;
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7180 isn->isn_arg.jump.jump_where = instr->ga_len;
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7181 }
21371
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21353
diff changeset
7182 }
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21353
diff changeset
7183
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7184 compile_endblock(cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7185
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7186 if (cctx->ctx_skip != SKIP_YES && generate_instr(cctx, ISN_ENDTRY) == NULL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7187 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7188 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7189 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7190
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7191 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7192 * compile "throw {expr}"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7193 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7194 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7195 compile_throw(char_u *arg, cctx_T *cctx UNUSED)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7196 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7197 char_u *p = skipwhite(arg);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7198
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
7199 if (compile_expr0(&p, cctx) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7200 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7201 if (may_generate_2STRING(-1, cctx) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7202 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7203 if (generate_instr_drop(cctx, ISN_THROW, 1) == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7204 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7205
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7206 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7207 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7208
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7209 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7210 * compile "echo expr"
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
7211 * compile "echomsg expr"
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
7212 * compile "echoerr expr"
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
7213 * compile "execute expr"
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7214 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7215 static char_u *
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
7216 compile_mult_expr(char_u *arg, int cmdidx, cctx_T *cctx)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7217 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7218 char_u *p = arg;
23183
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
7219 char_u *prev = arg;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7220 int count = 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7221
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
7222 for (;;)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7223 {
23183
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
7224 if (ends_excmd2(prev, p))
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
7225 break;
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
7226 if (compile_expr0(&p, cctx) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7227 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7228 ++count;
21835
b530ead4265a patch 8.2.1467: Vim9: :echomsg doesn't like a dict argument
Bram Moolenaar <Bram@vim.org>
parents: 21833
diff changeset
7229 prev = p;
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
7230 p = skipwhite(p);
23183
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
7231 }
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
7232
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
7233 if (count > 0)
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
7234 {
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
7235 if (cmdidx == CMD_echo || cmdidx == CMD_echon)
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
7236 generate_ECHO(cctx, cmdidx == CMD_echo, count);
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
7237 else if (cmdidx == CMD_execute)
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
7238 generate_MULT_EXPR(cctx, ISN_EXECUTE, count);
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
7239 else if (cmdidx == CMD_echomsg)
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
7240 generate_MULT_EXPR(cctx, ISN_ECHOMSG, count);
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
7241 else
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
7242 generate_MULT_EXPR(cctx, ISN_ECHOERR, count);
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
7243 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7244 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7245 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7246
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7247 /*
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 23199
diff changeset
7248 * If "eap" has a range that is not a constant generate an ISN_RANGE
23156
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7249 * instruction to compute it and return OK.
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7250 * Otherwise return FAIL, the caller must deal with any range.
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7251 */
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7252 static int
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7253 compile_variable_range(exarg_T *eap, cctx_T *cctx)
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7254 {
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7255 char_u *range_end = skip_range(eap->cmd, TRUE, NULL);
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7256 char_u *p = skipdigits(eap->cmd);
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7257
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7258 if (p == range_end)
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7259 return FAIL;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7260 return generate_RANGE(cctx, vim_strnsave(eap->cmd, range_end - eap->cmd));
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7261 }
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7262
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7263 /*
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7264 * :put r
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7265 * :put ={expr}
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7266 */
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7267 static char_u *
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7268 compile_put(char_u *arg, exarg_T *eap, cctx_T *cctx)
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7269 {
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7270 char_u *line = arg;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7271 linenr_T lnum;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7272 char *errormsg;
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
7273 int above = eap->forceit;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
7274
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7275 eap->regname = *line;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7276
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7277 if (eap->regname == '=')
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7278 {
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7279 char_u *p = line + 1;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7280
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7281 if (compile_expr0(&p, cctx) == FAIL)
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7282 return NULL;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7283 line = p;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7284 }
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7285 else if (eap->regname != NUL)
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7286 ++line;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7287
23156
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7288 if (compile_variable_range(eap, cctx) == OK)
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7289 {
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7290 lnum = above ? LNUM_VARIABLE_RANGE_ABOVE : LNUM_VARIABLE_RANGE;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7291 }
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7292 else
23156
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7293 {
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7294 // Either no range or a number.
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7295 // "errormsg" will not be set because the range is ADDR_LINES.
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7296 if (parse_cmd_address(eap, &errormsg, FALSE) == FAIL)
23199
59f31d2eb4cf patch 8.2.2145: Vim9: concatenating lists does not adjust type of result
Bram Moolenaar <Bram@vim.org>
parents: 23195
diff changeset
7297 // cannot happen
23156
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7298 return NULL;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7299 if (eap->addr_count == 0)
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7300 lnum = -1;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7301 else
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7302 lnum = eap->line2;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7303 if (above)
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7304 --lnum;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
7305 }
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7306
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7307 generate_PUT(cctx, eap->regname, lnum);
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7308 return line;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7309 }
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7310
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7311 /*
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7312 * A command that is not compiled, execute with legacy code.
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7313 */
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7314 static char_u *
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7315 compile_exec(char_u *line, exarg_T *eap, cctx_T *cctx)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7316 {
20172
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
7317 char_u *p;
20174
72b437855299 patch 8.2.0642: Vim9: using invalid index
Bram Moolenaar <Bram@vim.org>
parents: 20172
diff changeset
7318 int has_expr = FALSE;
21156
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7319 char_u *nextcmd = (char_u *)"";
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7320
20907
4eeda7139133 patch 8.2.1005: Vim9: using TRUE/FALSE/MAYBE for ctx_skip is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20899
diff changeset
7321 if (cctx->ctx_skip == SKIP_YES)
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7322 goto theend;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7323
20174
72b437855299 patch 8.2.0642: Vim9: using invalid index
Bram Moolenaar <Bram@vim.org>
parents: 20172
diff changeset
7324 if (eap->cmdidx >= 0 && eap->cmdidx < CMD_SIZE)
21156
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7325 {
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
7326 long argt = eap->argt;
21156
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7327 int usefilter = FALSE;
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7328
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7329 has_expr = argt & (EX_XFILE | EX_EXPAND);
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7330
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7331 // If the command can be followed by a bar, find the bar and truncate
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7332 // it, so that the following command can be compiled.
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7333 // The '|' is overwritten with a NUL, it is put back below.
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7334 if ((eap->cmdidx == CMD_write || eap->cmdidx == CMD_read)
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7335 && *eap->arg == '!')
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7336 // :w !filter or :r !filter or :r! filter
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7337 usefilter = TRUE;
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7338 if ((argt & EX_TRLBAR) && !usefilter)
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7339 {
21893
f19ac9b8b011 patch 8.2.1496: Vim9: cannot use " #" in a mapping
Bram Moolenaar <Bram@vim.org>
parents: 21883
diff changeset
7340 eap->argt = argt;
21156
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7341 separate_nextcmd(eap);
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7342 if (eap->nextcmd != NULL)
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7343 nextcmd = eap->nextcmd;
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7344 }
23477
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
7345 else if (eap->cmdidx == CMD_wincmd)
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
7346 {
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
7347 p = eap->arg;
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
7348 if (*p != NUL)
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
7349 ++p;
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
7350 if (*p == 'g' || *p == Ctrl_G)
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
7351 ++p;
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
7352 p = skipwhite(p);
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
7353 if (*p == '|')
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
7354 {
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
7355 *p = NUL;
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
7356 nextcmd = p + 1;
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
7357 }
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
7358 }
21156
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7359 }
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7360
20172
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
7361 if (eap->cmdidx == CMD_syntax && STRNCMP(eap->arg, "include ", 8) == 0)
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
7362 {
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
7363 // expand filename in "syntax include [@group] filename"
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
7364 has_expr = TRUE;
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
7365 eap->arg = skipwhite(eap->arg + 7);
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
7366 if (*eap->arg == '@')
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
7367 eap->arg = skiptowhite(eap->arg);
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
7368 }
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
7369
23344
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
7370 if ((eap->cmdidx == CMD_global || eap->cmdidx == CMD_vglobal)
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
7371 && STRLEN(eap->arg) > 4)
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
7372 {
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
7373 int delim = *eap->arg;
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
7374
23505
bb29b09902d5 patch 8.2.2295: incsearch does not detect empty pattern properly
Bram Moolenaar <Bram@vim.org>
parents: 23497
diff changeset
7375 p = skip_regexp_ex(eap->arg + 1, delim, TRUE, NULL, NULL, NULL);
23344
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
7376 if (*p == delim)
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
7377 {
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
7378 eap->arg = p + 1;
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
7379 has_expr = TRUE;
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
7380 }
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
7381 }
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
7382
20172
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
7383 if (has_expr && (p = (char_u *)strstr((char *)eap->arg, "`=")) != NULL)
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7384 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7385 int count = 0;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7386 char_u *start = skipwhite(line);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7387
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7388 // :cmd xxx`=expr1`yyy`=expr2`zzz
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7389 // PUSHS ":cmd xxx"
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7390 // eval expr1
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7391 // PUSHS "yyy"
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7392 // eval expr2
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7393 // PUSHS "zzz"
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7394 // EXECCONCAT 5
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7395 for (;;)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7396 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7397 if (p > start)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7398 {
20830
9064044fd4f6 patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
7399 generate_PUSHS(cctx, vim_strnsave(start, p - start));
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7400 ++count;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7401 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7402 p += 2;
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
7403 if (compile_expr0(&p, cctx) == FAIL)
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7404 return NULL;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7405 may_generate_2STRING(-1, cctx);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7406 ++count;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7407 p = skipwhite(p);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7408 if (*p != '`')
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7409 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
7410 emsg(_(e_missing_backtick));
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7411 return NULL;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7412 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7413 start = p + 1;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7414
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7415 p = (char_u *)strstr((char *)start, "`=");
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7416 if (p == NULL)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7417 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7418 if (*skipwhite(start) != NUL)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7419 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7420 generate_PUSHS(cctx, vim_strsave(start));
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7421 ++count;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7422 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7423 break;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7424 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7425 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7426 generate_EXECCONCAT(cctx, count);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7427 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7428 else
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7429 generate_EXEC(cctx, line);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7430
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7431 theend:
21156
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7432 if (*nextcmd != NUL)
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7433 {
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7434 // the parser expects a pointer to the bar, put it back
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7435 --nextcmd;
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7436 *nextcmd = '|';
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7437 }
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7438
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
7439 return nextcmd;
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7440 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7441
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
7442 /*
20339
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7443 * Add a function to the list of :def functions.
20943
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
7444 * This sets "ufunc->uf_dfunc_idx" but the function isn't compiled yet.
20339
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7445 */
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20419
diff changeset
7446 static int
20339
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7447 add_def_function(ufunc_T *ufunc)
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7448 {
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7449 dfunc_T *dfunc;
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7450
20943
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
7451 if (def_functions.ga_len == 0)
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
7452 {
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
7453 // The first position is not used, so that a zero uf_dfunc_idx means it
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
7454 // wasn't set.
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
7455 if (ga_grow(&def_functions, 1) == FAIL)
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
7456 return FAIL;
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
7457 ++def_functions.ga_len;
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
7458 }
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
7459
20339
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7460 // Add the function to "def_functions".
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7461 if (ga_grow(&def_functions, 1) == FAIL)
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7462 return FAIL;
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7463 dfunc = ((dfunc_T *)def_functions.ga_data) + def_functions.ga_len;
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7464 CLEAR_POINTER(dfunc);
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7465 dfunc->df_idx = def_functions.ga_len;
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7466 ufunc->uf_dfunc_idx = dfunc->df_idx;
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7467 dfunc->df_ufunc = ufunc;
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
7468 dfunc->df_name = vim_strsave(ufunc->uf_name);
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
7469 ++dfunc->df_refcount;
20339
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7470 ++def_functions.ga_len;
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7471 return OK;
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7472 }
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7473
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7474 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7475 * After ex_function() has collected all the function lines: parse and compile
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7476 * the lines into instructions.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7477 * Adds the function to "def_functions".
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
7478 * When "check_return_type" is set then set ufunc->uf_ret_type to the type of
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
7479 * the return statement (used for lambda). When uf_ret_type is already set
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
7480 * then check that it matches.
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
7481 * "outer_cctx" is set for a nested function.
19864
8288884fdfe1 patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents: 19862
diff changeset
7482 * This can be used recursively through compile_lambda(), which may reallocate
8288884fdfe1 patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents: 19862
diff changeset
7483 * "def_functions".
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20419
diff changeset
7484 * Returns OK or FAIL.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7485 */
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20419
diff changeset
7486 int
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
7487 compile_def_function(ufunc_T *ufunc, int check_return_type, cctx_T *outer_cctx)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7488 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7489 char_u *line = NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7490 char_u *p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7491 char *errormsg = NULL; // error message
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7492 cctx_T cctx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7493 garray_T *instr;
22758
48feb3dd0d25 patch 8.2.1927: Vim9: get unknown error with an error in a timer function
Bram Moolenaar <Bram@vim.org>
parents: 22734
diff changeset
7494 int did_emsg_before = did_emsg;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7495 int ret = FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7496 sctx_T save_current_sctx = current_sctx;
22584
c271498e03b2 patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
7497 int save_estack_compiling = estack_compiling;
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
7498 int do_estack_push;
21463
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
7499 int new_def_function = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7500
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
7501 // When using a function that was compiled before: Free old instructions.
23360
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
7502 // The index is reused. Otherwise add a new entry in "def_functions".
20943
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
7503 if (ufunc->uf_dfunc_idx > 0)
20339
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7504 {
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7505 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7506 + ufunc->uf_dfunc_idx;
23360
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
7507 delete_def_function_contents(dfunc, FALSE);
20339
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
7508 }
21463
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
7509 else
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
7510 {
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
7511 if (add_def_function(ufunc) == FAIL)
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
7512 return FAIL;
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
7513 new_def_function = TRUE;
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
7514 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7515
21281
13b1567ae0c6 patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
7516 ufunc->uf_def_status = UF_COMPILING;
13b1567ae0c6 patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
7517
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 20005
diff changeset
7518 CLEAR_FIELD(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7519 cctx.ctx_ufunc = ufunc;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7520 cctx.ctx_lnum = -1;
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
7521 cctx.ctx_outer = outer_cctx;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7522 ga_init2(&cctx.ctx_locals, sizeof(lvar_T), 10);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7523 ga_init2(&cctx.ctx_type_stack, sizeof(type_T *), 50);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7524 ga_init2(&cctx.ctx_imports, sizeof(imported_T), 10);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7525 cctx.ctx_type_list = &ufunc->uf_type_list;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7526 ga_init2(&cctx.ctx_instr, sizeof(isn_T), 50);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7527 instr = &cctx.ctx_instr;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7528
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
7529 // Set the context to the function, it may be compiled when called from
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
7530 // another script. Set the script version to the most modern one.
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
7531 // The line number will be set in next_line_from_context().
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
7532 current_sctx = ufunc->uf_script_ctx;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7533 current_sctx.sc_version = SCRIPT_VERSION_VIM9;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7534
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
7535 // Make sure error messages are OK.
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
7536 do_estack_push = !estack_top_is_ufunc(ufunc, 1);
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
7537 if (do_estack_push)
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
7538 estack_push_ufunc(ufunc, 1);
22584
c271498e03b2 patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
7539 estack_compiling = TRUE;
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
7540
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7541 if (ufunc->uf_def_args.ga_len > 0)
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7542 {
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7543 int count = ufunc->uf_def_args.ga_len;
19946
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
7544 int first_def_arg = ufunc->uf_args.ga_len - count;
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7545 int i;
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7546 char_u *arg;
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7547 int off = STACK_FRAME_SIZE + (ufunc->uf_va_name != NULL ? 1 : 0);
21469
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
7548 int did_set_arg_type = FALSE;
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7549
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7550 // Produce instructions for the default values of optional arguments.
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7551 // Store the instruction index in uf_def_arg_idx[] so that we know
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7552 // where to start when the function is called, depending on the number
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7553 // of arguments.
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7554 ufunc->uf_def_arg_idx = ALLOC_CLEAR_MULT(int, count + 1);
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7555 if (ufunc->uf_def_arg_idx == NULL)
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7556 goto erret;
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7557 for (i = 0; i < count; ++i)
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7558 {
19946
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
7559 garray_T *stack = &cctx.ctx_type_stack;
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
7560 type_T *val_type;
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
7561 int arg_idx = first_def_arg + i;
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
7562
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7563 ufunc->uf_def_arg_idx[i] = instr->ga_len;
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7564 arg = ((char_u **)(ufunc->uf_def_args.ga_data))[i];
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
7565 if (compile_expr0(&arg, &cctx) == FAIL)
19946
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
7566 goto erret;
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
7567
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
7568 // If no type specified use the type of the default value.
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
7569 // Otherwise check that the default value type matches the
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
7570 // specified type.
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
7571 val_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
7572 if (ufunc->uf_arg_types[arg_idx] == &t_unknown)
21469
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
7573 {
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
7574 did_set_arg_type = TRUE;
19946
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
7575 ufunc->uf_arg_types[arg_idx] = val_type;
21469
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
7576 }
22004
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
7577 else if (check_type(ufunc->uf_arg_types[arg_idx], val_type,
a9e60176dcd3 patch 8.2.1551: Vim9: error for argument type does not mention the number
Bram Moolenaar <Bram@vim.org>
parents: 21979
diff changeset
7578 TRUE, arg_idx + 1) == FAIL)
19946
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
7579 goto erret;
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
7580
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
7581 if (generate_STORE(&cctx, ISN_STORE, i - count - off, NULL) == FAIL)
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7582 goto erret;
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7583 }
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7584 ufunc->uf_def_arg_idx[count] = instr->ga_len;
21469
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
7585
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
7586 if (did_set_arg_type)
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
7587 set_function_type(ufunc);
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7588 }
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7589
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7590 /*
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7591 * Loop over all the lines of the function and generate instructions.
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
7592 */
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7593 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7594 {
21689
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21683
diff changeset
7595 exarg_T ea;
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21683
diff changeset
7596 int starts_with_colon = FALSE;
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21683
diff changeset
7597 char_u *cmd;
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
7598 cmdmod_T local_cmdmod;
19473
b09afbebffee patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
7599
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
7600 // Bail out on the first error to avoid a flood of errors and report
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
7601 // the right line number when inside try/catch.
22758
48feb3dd0d25 patch 8.2.1927: Vim9: get unknown error with an error in a timer function
Bram Moolenaar <Bram@vim.org>
parents: 22734
diff changeset
7602 if (did_emsg_before != did_emsg)
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
7603 goto erret;
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
7604
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7605 if (line != NULL && *line == '|')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7606 // the line continues after a '|'
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7607 ++line;
20949
62912ad41aff patch 8.2.1026: Vim9: cannot break the line after "->"
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
7608 else if (line != NULL && *skipwhite(line) != NUL
20059
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20055
diff changeset
7609 && !(*line == '#' && (line == cctx.ctx_line_start
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20055
diff changeset
7610 || VIM_ISWHITE(line[-1]))))
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7611 {
21455
8cc1555f2445 patch 8.2.1278: Vim9: line break after "->" only allowed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21443
diff changeset
7612 semsg(_(e_trailing_arg), line);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7613 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7614 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7615 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7616 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
7617 line = next_line_from_context(&cctx, FALSE);
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
7618 if (cctx.ctx_lnum >= ufunc->uf_lines.ga_len)
20055
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7619 // beyond the last line
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7620 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7621 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7622
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 20005
diff changeset
7623 CLEAR_FIELD(ea);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7624 ea.cmdlinep = &line;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7625 ea.cmd = skipwhite(line);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7626
20055
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7627 // Some things can be recognized by the first character.
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7628 switch (*ea.cmd)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7629 {
20055
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7630 case '#':
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
7631 // "#" starts a comment
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
7632 line = (char_u *)"";
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
7633 continue;
20055
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7634
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7635 case '}':
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7636 {
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7637 // "}" ends a block scope
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7638 scopetype_T stype = cctx.ctx_scope == NULL
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7639 ? NO_SCOPE : cctx.ctx_scope->se_type;
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7640
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7641 if (stype == BLOCK_SCOPE)
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7642 {
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7643 compile_endblock(&cctx);
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7644 line = ea.cmd;
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7645 }
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7646 else
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7647 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
7648 emsg(_(e_using_rcurly_outside_if_block_scope));
20055
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7649 goto erret;
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7650 }
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7651 if (line != NULL)
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7652 line = skipwhite(ea.cmd + 1);
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7653 continue;
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7654 }
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7655
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7656 case '{':
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7657 // "{" starts a block scope
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7658 // "{'a': 1}->func() is something else
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7659 if (ends_excmd(*skipwhite(ea.cmd + 1)))
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7660 {
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7661 line = compile_block(ea.cmd, &cctx);
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7662 continue;
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7663 }
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
7664 break;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7665 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7666
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7667 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7668 * COMMAND MODIFIERS
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7669 */
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
7670 cctx.ctx_has_cmdmod = FALSE;
22699
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 22697
diff changeset
7671 if (parse_command_modifiers(&ea, &errormsg, &local_cmdmod, FALSE)
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 22697
diff changeset
7672 == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7673 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7674 if (errormsg != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7675 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7676 // empty line or comment
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7677 line = (char_u *)"";
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7678 continue;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7679 }
22699
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 22697
diff changeset
7680 generate_cmdmods(&cctx, &local_cmdmod);
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 22697
diff changeset
7681 undo_cmdmod(&local_cmdmod);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7682
22772
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
7683 // Check if there was a colon after the last command modifier or before
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
7684 // the current position.
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
7685 for (p = ea.cmd; p >= line; --p)
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
7686 {
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
7687 if (*p == ':')
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
7688 starts_with_colon = TRUE;
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
7689 if (p < ea.cmd && !VIM_ISWHITE(*p))
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
7690 break;
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
7691 }
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
7692
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7693 // Skip ":call" to get to the function name.
21751
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21743
diff changeset
7694 p = ea.cmd;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7695 if (checkforcmd(&ea.cmd, "call", 3))
21751
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21743
diff changeset
7696 {
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21743
diff changeset
7697 if (*ea.cmd == '(')
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21743
diff changeset
7698 // not for "call()"
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21743
diff changeset
7699 ea.cmd = p;
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21743
diff changeset
7700 else
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21743
diff changeset
7701 ea.cmd = skipwhite(ea.cmd);
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21743
diff changeset
7702 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7703
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
7704 if (!starts_with_colon)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7705 {
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
7706 char_u *pskip;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
7707
19473
b09afbebffee patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
7708 // Assuming the command starts with a variable or function name,
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
7709 // find what follows.
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
7710 // Skip over "var.member", "var[idx]" and the like.
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
7711 // Also "&opt = val", "$ENV = val" and "@r = val".
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
7712 pskip = (*ea.cmd == '&' || *ea.cmd == '$' || *ea.cmd == '@')
19473
b09afbebffee patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
7713 ? ea.cmd + 1 : ea.cmd;
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
7714 p = to_name_end(pskip, TRUE);
19862
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19860
diff changeset
7715 if (p > ea.cmd && *p != NUL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7716 {
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
7717 char_u *var_end;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
7718 int oplen;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
7719 int heredoc;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
7720
21614
d0128ecd4341 patch 8.2.1357: Vim9: cannot assign to / register
Bram Moolenaar <Bram@vim.org>
parents: 21612
diff changeset
7721 if (ea.cmd[0] == '@')
d0128ecd4341 patch 8.2.1357: Vim9: cannot assign to / register
Bram Moolenaar <Bram@vim.org>
parents: 21612
diff changeset
7722 var_end = ea.cmd + 2;
d0128ecd4341 patch 8.2.1357: Vim9: cannot assign to / register
Bram Moolenaar <Bram@vim.org>
parents: 21612
diff changeset
7723 else
d0128ecd4341 patch 8.2.1357: Vim9: cannot assign to / register
Bram Moolenaar <Bram@vim.org>
parents: 21612
diff changeset
7724 var_end = find_name_end(pskip, NULL, NULL,
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
7725 FNE_CHECK_START | FNE_INCL_BR);
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
7726 oplen = assignment_len(skipwhite(var_end), &heredoc);
19473
b09afbebffee patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
7727 if (oplen > 0)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7728 {
20355
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20349
diff changeset
7729 size_t len = p - ea.cmd;
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20349
diff changeset
7730
19473
b09afbebffee patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
7731 // Recognize an assignment if we recognize the variable
b09afbebffee patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
7732 // name:
b09afbebffee patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
7733 // "g:var = expr"
19583
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
7734 // "local = expr" where "local" is a local var.
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
7735 // "script = expr" where "script" is a script-local var.
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
7736 // "import = expr" where "import" is an imported var
19473
b09afbebffee patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
7737 // "&opt = expr"
b09afbebffee patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
7738 // "$ENV = expr"
b09afbebffee patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
7739 // "@r = expr"
b09afbebffee patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
7740 if (*ea.cmd == '&'
b09afbebffee patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
7741 || *ea.cmd == '$'
b09afbebffee patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
7742 || *ea.cmd == '@'
20355
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20349
diff changeset
7743 || ((len) > 2 && ea.cmd[1] == ':')
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
7744 || lookup_local(ea.cmd, len, NULL, &cctx) == OK
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
7745 || arg_exists(ea.cmd, len, NULL, NULL,
20355
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20349
diff changeset
7746 NULL, &cctx) == OK
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
7747 || script_var_exists(ea.cmd, len,
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
7748 FALSE, &cctx) == OK
20355
fc2d76e0994c patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents: 20349
diff changeset
7749 || find_imported(ea.cmd, len, &cctx) != NULL)
19473
b09afbebffee patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
7750 {
b09afbebffee patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
7751 line = compile_assignment(ea.cmd, &ea, CMD_SIZE, &cctx);
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
7752 if (line == NULL || line == ea.cmd)
19473
b09afbebffee patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
7753 goto erret;
23100
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23088
diff changeset
7754 goto nextline;
19473
b09afbebffee patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
7755 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7756 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7757 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
7758
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
7759 if (*ea.cmd == '[')
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
7760 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
7761 // [var, var] = expr
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
7762 line = compile_assignment(ea.cmd, &ea, CMD_SIZE, &cctx);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
7763 if (line == NULL)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
7764 goto erret;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
7765 if (line != ea.cmd)
23100
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23088
diff changeset
7766 goto nextline;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
7767 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7768 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7769
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7770 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7771 * COMMAND after range
21335
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
7772 * 'text'->func() should not be confused with 'a mark
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7773 */
20982
bb49b5090a9c patch 8.2.1042: Vim9: cannot put an operator on the next line
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
7774 cmd = ea.cmd;
21755
3b312e56e2b8 patch 8.2.1427: Vim9: cannot use a range with marks in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21753
diff changeset
7775 if (*cmd != '\'' || starts_with_colon)
20982
bb49b5090a9c patch 8.2.1042: Vim9: cannot put an operator on the next line
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
7776 {
22260
d7c1e3efa88e patch 8.2.1679: Vim9: ":*" is not recognized as a range
Bram Moolenaar <Bram@vim.org>
parents: 22236
diff changeset
7777 ea.cmd = skip_range(ea.cmd, TRUE, NULL);
21901
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
7778 if (ea.cmd > cmd)
21335
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
7779 {
21901
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
7780 if (!starts_with_colon)
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
7781 {
23346
2060f53b7c17 patch 8.2.2216: Vim9: range with missing colon can be hard to spot
Bram Moolenaar <Bram@vim.org>
parents: 23344
diff changeset
7782 semsg(_(e_colon_required_before_range_str), cmd);
21901
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
7783 goto erret;
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
7784 }
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
7785 if (ends_excmd2(line, ea.cmd))
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
7786 {
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
7787 // A range without a command: jump to the line.
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
7788 // TODO: compile to a more efficient command, possibly
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
7789 // calling parse_cmd_address().
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
7790 ea.cmdidx = CMD_SIZE;
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
7791 line = compile_exec(line, &ea, &cctx);
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
7792 goto nextline;
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
7793 }
21335
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
7794 }
20982
bb49b5090a9c patch 8.2.1042: Vim9: cannot put an operator on the next line
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
7795 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
7796 p = find_ex_command(&ea, NULL, starts_with_colon ? NULL
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
7797 : (int (*)(char_u *, size_t, void *, cctx_T *))lookup_local,
19473
b09afbebffee patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents: 19467
diff changeset
7798 &cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7799
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7800 if (p == ea.cmd && ea.cmdidx != CMD_SIZE)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7801 {
20907
4eeda7139133 patch 8.2.1005: Vim9: using TRUE/FALSE/MAYBE for ctx_skip is confusing
Bram Moolenaar <Bram@vim.org>
parents: 20899
diff changeset
7802 if (cctx.ctx_skip == SKIP_YES)
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7803 {
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7804 line += STRLEN(line);
23100
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23088
diff changeset
7805 goto nextline;
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7806 }
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7807
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7808 // Expression or function call.
21196
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
7809 if (ea.cmdidx != CMD_eval)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7810 {
23254
4b7e996354e0 patch 8.2.2173: Vim9: get internal error when assigning to undefined variable
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
7811 // CMD_var cannot happen, compile_assignment() above would be
4b7e996354e0 patch 8.2.2173: Vim9: get internal error when assigning to undefined variable
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
7812 // used. Most likely an assignment to a non-existing variable.
4b7e996354e0 patch 8.2.2173: Vim9: get internal error when assigning to undefined variable
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
7813 semsg(_(e_command_not_recognized_str), ea.cmd);
21196
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
7814 goto erret;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7815 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7816 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7817
21957
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
7818 if (cctx.ctx_had_return
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7819 && ea.cmdidx != CMD_elseif
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7820 && ea.cmdidx != CMD_else
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7821 && ea.cmdidx != CMD_endif
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7822 && ea.cmdidx != CMD_endfor
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7823 && ea.cmdidx != CMD_endwhile
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7824 && ea.cmdidx != CMD_catch
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7825 && ea.cmdidx != CMD_finally
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7826 && ea.cmdidx != CMD_endtry)
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7827 {
21957
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
7828 emsg(_(e_unreachable_code_after_return));
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
7829 goto erret;
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7830 }
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7831
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
7832 p = skipwhite(p);
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
7833 if (ea.cmdidx != CMD_SIZE
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
7834 && ea.cmdidx != CMD_write && ea.cmdidx != CMD_read)
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
7835 {
22276
753452747ae5 patch 8.2.1687: Vim9: out of bounds error
Bram Moolenaar <Bram@vim.org>
parents: 22274
diff changeset
7836 if (ea.cmdidx >= 0)
753452747ae5 patch 8.2.1687: Vim9: out of bounds error
Bram Moolenaar <Bram@vim.org>
parents: 22274
diff changeset
7837 ea.argt = excmd_get_argt(ea.cmdidx);
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
7838 if ((ea.argt & EX_BANG) && *p == '!')
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
7839 {
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
7840 ea.forceit = TRUE;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
7841 p = skipwhite(p + 1);
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
7842 }
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
7843 }
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
7844
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7845 switch (ea.cmdidx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7846 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7847 case CMD_def:
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
7848 ea.arg = p;
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
7849 line = compile_nested_function(&ea, &cctx);
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
7850 break;
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
7851
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7852 case CMD_function:
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
7853 // TODO: should we allow this, e.g. to declare a global
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
7854 // function?
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
7855 emsg(_(e_cannot_use_function_inside_def));
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7856 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7857
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7858 case CMD_return:
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
7859 line = compile_return(p, check_return_type, &cctx);
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7860 cctx.ctx_had_return = TRUE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7861 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7862
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7863 case CMD_let:
22667
87987c783087 patch 8.2.1882: Vim9: v:disallow_let is no longer needed
Bram Moolenaar <Bram@vim.org>
parents: 22663
diff changeset
7864 emsg(_(e_cannot_use_let_in_vim9_script));
87987c783087 patch 8.2.1882: Vim9: v:disallow_let is no longer needed
Bram Moolenaar <Bram@vim.org>
parents: 22663
diff changeset
7865 break;
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
7866 case CMD_var:
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
7867 case CMD_final:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7868 case CMD_const:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7869 line = compile_assignment(p, &ea, ea.cmdidx, &cctx);
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
7870 if (line == p)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
7871 line = NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7872 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7873
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7874 case CMD_unlet:
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7875 case CMD_unlockvar:
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7876 case CMD_lockvar:
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7877 line = compile_unletlock(p, &ea, &cctx);
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7878 break;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7879
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7880 case CMD_import:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7881 line = compile_import(p, &cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7882 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7883
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7884 case CMD_if:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7885 line = compile_if(p, &cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7886 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7887 case CMD_elseif:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7888 line = compile_elseif(p, &cctx);
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7889 cctx.ctx_had_return = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7890 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7891 case CMD_else:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7892 line = compile_else(p, &cctx);
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7893 cctx.ctx_had_return = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7894 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7895 case CMD_endif:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7896 line = compile_endif(p, &cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7897 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7898
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7899 case CMD_while:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7900 line = compile_while(p, &cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7901 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7902 case CMD_endwhile:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7903 line = compile_endwhile(p, &cctx);
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7904 cctx.ctx_had_return = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7905 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7906
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7907 case CMD_for:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7908 line = compile_for(p, &cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7909 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7910 case CMD_endfor:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7911 line = compile_endfor(p, &cctx);
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7912 cctx.ctx_had_return = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7913 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7914 case CMD_continue:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7915 line = compile_continue(p, &cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7916 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7917 case CMD_break:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7918 line = compile_break(p, &cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7919 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7920
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7921 case CMD_try:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7922 line = compile_try(p, &cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7923 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7924 case CMD_catch:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7925 line = compile_catch(p, &cctx);
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7926 cctx.ctx_had_return = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7927 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7928 case CMD_finally:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7929 line = compile_finally(p, &cctx);
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7930 cctx.ctx_had_return = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7931 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7932 case CMD_endtry:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7933 line = compile_endtry(p, &cctx);
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7934 cctx.ctx_had_return = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7935 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7936 case CMD_throw:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7937 line = compile_throw(p, &cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7938 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7939
21196
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
7940 case CMD_eval:
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
7941 if (compile_expr0(&p, &cctx) == FAIL)
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
7942 goto erret;
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
7943
21957
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
7944 // drop the result
21196
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
7945 generate_instr_drop(&cctx, ISN_DROP, 1);
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
7946
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
7947 line = skipwhite(p);
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
7948 break;
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
7949
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7950 case CMD_echo:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7951 case CMD_echon:
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
7952 case CMD_execute:
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
7953 case CMD_echomsg:
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
7954 case CMD_echoerr:
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
7955 line = compile_mult_expr(p, ea.cmdidx, &cctx);
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
7956 break;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7957
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7958 case CMD_put:
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7959 ea.cmd = cmd;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7960 line = compile_put(p, &ea, &cctx);
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7961 break;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
7962
21957
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
7963 // TODO: any other commands with an expression argument?
20982
bb49b5090a9c patch 8.2.1042: Vim9: cannot put an operator on the next line
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
7964
21516
c7b2ce90c2de patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
7965 case CMD_append:
c7b2ce90c2de patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
7966 case CMD_change:
c7b2ce90c2de patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
7967 case CMD_insert:
21584
d0c76ce48326 patch 8.2.1342: Vim9: accidentally using "t" gives a confusing error
Bram Moolenaar <Bram@vim.org>
parents: 21578
diff changeset
7968 case CMD_t:
21516
c7b2ce90c2de patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
7969 case CMD_xit:
c7b2ce90c2de patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
7970 not_in_vim9(&ea);
c7b2ce90c2de patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
7971 goto erret;
c7b2ce90c2de patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
7972
21210
44611891e22c patch 8.2.1156: Vim9: No error for invalid command in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
7973 case CMD_SIZE:
21957
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
7974 if (cctx.ctx_skip != SKIP_YES)
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
7975 {
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
7976 semsg(_(e_invalid_command_str), ea.cmd);
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
7977 goto erret;
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
7978 }
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
7979 // We don't check for a next command here.
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
7980 line = (char_u *)"";
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
7981 break;
21210
44611891e22c patch 8.2.1156: Vim9: No error for invalid command in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
7982
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7983 default:
21961
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
7984 if (cctx.ctx_skip == SKIP_YES)
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
7985 {
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
7986 // We don't check for a next command here.
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
7987 line = (char_u *)"";
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
7988 }
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
7989 else
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
7990 {
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
7991 // Not recognized, execute with do_cmdline_cmd().
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
7992 ea.arg = p;
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
7993 line = compile_exec(line, &ea, &cctx);
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
7994 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7995 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7996 }
21901
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
7997 nextline:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7998 if (line == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7999 goto erret;
19894
ea4f8e789627 patch 8.2.0503: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
8000 line = skipwhite(line);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8001
22691
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
8002 // Undo any command modifiers.
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
8003 generate_undo_cmdmods(&cctx);
22691
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
8004
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8005 if (cctx.ctx_type_stack.ga_len < 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8006 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8007 iemsg("Type stack underflow");
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8008 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8009 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8010 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8011
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8012 if (cctx.ctx_scope != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8013 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8014 if (cctx.ctx_scope->se_type == IF_SCOPE)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8015 emsg(_(e_endif));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8016 else if (cctx.ctx_scope->se_type == WHILE_SCOPE)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8017 emsg(_(e_endwhile));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8018 else if (cctx.ctx_scope->se_type == FOR_SCOPE)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8019 emsg(_(e_endfor));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8020 else
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
8021 emsg(_(e_missing_rcurly));
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8022 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8023 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8024
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
8025 if (!cctx.ctx_had_return)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8026 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8027 if (ufunc->uf_ret_type->tt_type != VAR_VOID)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8028 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
8029 emsg(_(e_missing_return_statement));
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8030 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8031 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8032
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8033 // Return zero if there is no return at the end.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8034 generate_PUSHNR(&cctx, 0);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8035 generate_instr(&cctx, ISN_RETURN);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8036 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8037
19864
8288884fdfe1 patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents: 19862
diff changeset
8038 {
8288884fdfe1 patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents: 19862
diff changeset
8039 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
8288884fdfe1 patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents: 19862
diff changeset
8040 + ufunc->uf_dfunc_idx;
8288884fdfe1 patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents: 19862
diff changeset
8041 dfunc->df_deleted = FALSE;
23330
e8eb4fd44902 patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents: 23318
diff changeset
8042 dfunc->df_script_seq = current_sctx.sc_seq;
19864
8288884fdfe1 patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents: 19862
diff changeset
8043 dfunc->df_instr = instr->ga_data;
8288884fdfe1 patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents: 19862
diff changeset
8044 dfunc->df_instr_count = instr->ga_len;
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
8045 dfunc->df_varcount = cctx.ctx_locals_count;
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22369
diff changeset
8046 dfunc->df_has_closure = cctx.ctx_has_closure;
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
8047 if (cctx.ctx_outer_used)
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
8048 ufunc->uf_flags |= FC_CLOSURE;
20943
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
8049 ufunc->uf_def_status = UF_COMPILED;
19864
8288884fdfe1 patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents: 19862
diff changeset
8050 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8051
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8052 ret = OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8053
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8054 erret:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8055 if (ret == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8056 {
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8057 int idx;
19864
8288884fdfe1 patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents: 19862
diff changeset
8058 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
8288884fdfe1 patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents: 19862
diff changeset
8059 + ufunc->uf_dfunc_idx;
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8060
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8061 for (idx = 0; idx < instr->ga_len; ++idx)
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8062 delete_instr(((isn_T *)instr->ga_data) + idx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8063 ga_clear(instr);
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8064 VIM_CLEAR(dfunc->df_name);
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8065
21463
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
8066 // If using the last entry in the table and it was added above, we
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
8067 // might as well remove it.
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
8068 if (!dfunc->df_deleted && new_def_function
20534
ae758aa4ee5e patch 8.2.0821: Vim9: memory leak in expr test
Bram Moolenaar <Bram@vim.org>
parents: 20532
diff changeset
8069 && ufunc->uf_dfunc_idx == def_functions.ga_len - 1)
21463
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
8070 {
20534
ae758aa4ee5e patch 8.2.0821: Vim9: memory leak in expr test
Bram Moolenaar <Bram@vim.org>
parents: 20532
diff changeset
8071 --def_functions.ga_len;
21463
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
8072 ufunc->uf_dfunc_idx = 0;
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
8073 }
20943
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
8074 ufunc->uf_def_status = UF_NOT_COMPILED;
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8075
19896
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
8076 while (cctx.ctx_scope != NULL)
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
8077 drop_scope(&cctx);
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
8078
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8079 // Don't execute this function body.
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8080 ga_clear_strings(&ufunc->uf_lines);
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8081
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8082 if (errormsg != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8083 emsg(errormsg);
22758
48feb3dd0d25 patch 8.2.1927: Vim9: get unknown error with an error in a timer function
Bram Moolenaar <Bram@vim.org>
parents: 22734
diff changeset
8084 else if (did_emsg == did_emsg_before)
22614
048a3033d19c patch 8.2.1855: Vim9: get error message when nothing is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22606
diff changeset
8085 emsg(_(e_compiling_def_function_failed));
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8086 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8087
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8088 current_sctx = save_current_sctx;
22584
c271498e03b2 patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22537
diff changeset
8089 estack_compiling = save_estack_compiling;
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
8090 if (do_estack_push)
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
8091 estack_pop();
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
8092
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8093 free_imported(&cctx);
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
8094 free_locals(&cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8095 ga_clear(&cctx.ctx_type_stack);
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20419
diff changeset
8096 return ret;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8097 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8098
20532
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8099 void
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8100 set_function_type(ufunc_T *ufunc)
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8101 {
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8102 int varargs = ufunc->uf_va_name != NULL;
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8103 int argcount = ufunc->uf_args.ga_len;
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8104
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8105 // Create a type for the function, with the return type and any
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8106 // argument types.
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8107 // A vararg is included in uf_args.ga_len but not in uf_arg_types.
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8108 // The type is included in "tt_args".
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8109 if (argcount > 0 || varargs)
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8110 {
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8111 ufunc->uf_func_type = alloc_func_type(ufunc->uf_ret_type,
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8112 argcount, &ufunc->uf_type_list);
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8113 // Add argument types to the function type.
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8114 if (func_type_add_arg_types(ufunc->uf_func_type,
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8115 argcount + varargs,
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8116 &ufunc->uf_type_list) == FAIL)
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8117 return;
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8118 ufunc->uf_func_type->tt_argcount = argcount + varargs;
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8119 ufunc->uf_func_type->tt_min_argcount =
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8120 argcount - ufunc->uf_def_args.ga_len;
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8121 if (ufunc->uf_arg_types == NULL)
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8122 {
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8123 int i;
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8124
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8125 // lambda does not have argument types.
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8126 for (i = 0; i < argcount; ++i)
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8127 ufunc->uf_func_type->tt_args[i] = &t_any;
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8128 }
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8129 else
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8130 mch_memmove(ufunc->uf_func_type->tt_args,
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8131 ufunc->uf_arg_types, sizeof(type_T *) * argcount);
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8132 if (varargs)
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8133 {
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8134 ufunc->uf_func_type->tt_args[argcount] =
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8135 ufunc->uf_va_type == NULL ? &t_any : ufunc->uf_va_type;
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8136 ufunc->uf_func_type->tt_flags = TTFLAG_VARARGS;
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8137 }
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8138 }
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8139 else
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8140 // No arguments, can use a predefined type.
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8141 ufunc->uf_func_type = get_func_type(ufunc->uf_ret_type,
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8142 argcount, &ufunc->uf_type_list);
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8143 }
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8144
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
8145
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8146 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8147 * Delete an instruction, free what it contains.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8148 */
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8149 void
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8150 delete_instr(isn_T *isn)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8151 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8152 switch (isn->isn_type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8153 {
22973
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
8154 case ISN_DEF:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8155 case ISN_EXEC:
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
8156 case ISN_LOADAUTO:
22973
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
8157 case ISN_LOADB:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8158 case ISN_LOADENV:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8159 case ISN_LOADG:
22973
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
8160 case ISN_LOADOPT:
20089
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
8161 case ISN_LOADT:
22973
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
8162 case ISN_LOADW:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8163 case ISN_PUSHEXC:
22973
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
8164 case ISN_PUSHFUNC:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8165 case ISN_PUSHS:
23156
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8166 case ISN_RANGE:
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
8167 case ISN_STOREAUTO:
22973
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
8168 case ISN_STOREB:
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
8169 case ISN_STOREENV:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8170 case ISN_STOREG:
22973
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
8171 case ISN_STORET:
20089
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
8172 case ISN_STOREW:
22973
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
8173 case ISN_STRINGMEMBER:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8174 vim_free(isn->isn_arg.string);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8175 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8176
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8177 case ISN_LOADS:
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
8178 case ISN_STORES:
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
8179 vim_free(isn->isn_arg.loadstore.ls_name);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8180 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8181
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
8182 case ISN_UNLET:
20099
058b41f85bcb patch 8.2.0605: Vim9: cannot unlet an environment variable
Bram Moolenaar <Bram@vim.org>
parents: 20091
diff changeset
8183 case ISN_UNLETENV:
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
8184 vim_free(isn->isn_arg.unlet.ul_name);
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
8185 break;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
8186
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8187 case ISN_STOREOPT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8188 vim_free(isn->isn_arg.storeopt.so_name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8189 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8190
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8191 case ISN_PUSHBLOB: // push blob isn_arg.blob
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8192 blob_unref(isn->isn_arg.blob);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8193 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8194
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
8195 case ISN_PUSHJOB:
19562
6b7719b8f9b9 patch 8.2.0338: build failure without the channel feature
Bram Moolenaar <Bram@vim.org>
parents: 19558
diff changeset
8196 #ifdef FEAT_JOB_CHANNEL
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
8197 job_unref(isn->isn_arg.job);
19562
6b7719b8f9b9 patch 8.2.0338: build failure without the channel feature
Bram Moolenaar <Bram@vim.org>
parents: 19558
diff changeset
8198 #endif
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
8199 break;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
8200
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
8201 case ISN_PUSHCHANNEL:
19562
6b7719b8f9b9 patch 8.2.0338: build failure without the channel feature
Bram Moolenaar <Bram@vim.org>
parents: 19558
diff changeset
8202 #ifdef FEAT_JOB_CHANNEL
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
8203 channel_unref(isn->isn_arg.channel);
19562
6b7719b8f9b9 patch 8.2.0338: build failure without the channel feature
Bram Moolenaar <Bram@vim.org>
parents: 19558
diff changeset
8204 #endif
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
8205 break;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
8206
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8207 case ISN_UCALL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8208 vim_free(isn->isn_arg.ufunc.cuf_name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8209 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8210
20283
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
8211 case ISN_FUNCREF:
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
8212 {
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
8213 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
8214 + isn->isn_arg.funcref.fr_func;
23289
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
8215 ufunc_T *ufunc = dfunc->df_ufunc;
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
8216
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
8217 if (ufunc != NULL && func_name_refcount(ufunc->uf_name))
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
8218 func_ptr_unref(ufunc);
22326
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
8219 }
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
8220 break;
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
8221
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
8222 case ISN_DCALL:
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
8223 {
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
8224 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
8225 + isn->isn_arg.dfunc.cdf_idx;
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
8226
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22369
diff changeset
8227 if (dfunc->df_ufunc != NULL
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22369
diff changeset
8228 && func_name_refcount(dfunc->df_ufunc->uf_name))
22326
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
8229 func_ptr_unref(dfunc->df_ufunc);
20283
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
8230 }
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
8231 break;
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
8232
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
8233 case ISN_NEWFUNC:
21564
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
8234 {
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
8235 char_u *lambda = isn->isn_arg.newfunc.nf_lambda;
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
8236 ufunc_T *ufunc = find_func_even_dead(lambda, TRUE, NULL);
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
8237
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
8238 if (ufunc != NULL)
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
8239 {
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8240 unlink_def_function(ufunc);
21564
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
8241 func_ptr_unref(ufunc);
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
8242 }
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
8243
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
8244 vim_free(lambda);
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
8245 vim_free(isn->isn_arg.newfunc.nf_global);
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
8246 }
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
8247 break;
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
8248
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
8249 case ISN_CHECKTYPE:
23458
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
8250 case ISN_SETTYPE:
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
8251 free_type(isn->isn_arg.type.ct_type);
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
8252 break;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
8253
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
8254 case ISN_CMDMOD:
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
8255 vim_regfree(isn->isn_arg.cmdmod.cf_cmdmod
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
8256 ->cmod_filter_regmatch.regprog);
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
8257 vim_free(isn->isn_arg.cmdmod.cf_cmdmod);
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
8258 break;
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
8259
23330
e8eb4fd44902 patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents: 23318
diff changeset
8260 case ISN_LOADSCRIPT:
e8eb4fd44902 patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents: 23318
diff changeset
8261 case ISN_STORESCRIPT:
e8eb4fd44902 patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents: 23318
diff changeset
8262 vim_free(isn->isn_arg.script.scriptref);
e8eb4fd44902 patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents: 23318
diff changeset
8263 break;
e8eb4fd44902 patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents: 23318
diff changeset
8264
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8265 case ISN_2BOOL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8266 case ISN_2STRING:
21771
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
8267 case ISN_2STRING_ANY:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8268 case ISN_ADDBLOB:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8269 case ISN_ADDLIST:
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
8270 case ISN_ANYINDEX:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
8271 case ISN_ANYSLICE:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8272 case ISN_BCALL:
22637
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
8273 case ISN_BLOBAPPEND:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8274 case ISN_CATCH:
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
8275 case ISN_CHECKLEN:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8276 case ISN_CHECKNR:
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
8277 case ISN_CMDMOD_REV:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8278 case ISN_COMPAREANY:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8279 case ISN_COMPAREBLOB:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8280 case ISN_COMPAREBOOL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8281 case ISN_COMPAREDICT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8282 case ISN_COMPAREFLOAT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8283 case ISN_COMPAREFUNC:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8284 case ISN_COMPARELIST:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8285 case ISN_COMPARENR:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8286 case ISN_COMPARESPECIAL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8287 case ISN_COMPARESTRING:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8288 case ISN_CONCAT:
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
8289 case ISN_COND2BOOL:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8290 case ISN_DROP:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8291 case ISN_ECHO:
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8292 case ISN_ECHOERR:
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
8293 case ISN_ECHOMSG:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8294 case ISN_ENDTRY:
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8295 case ISN_EXECCONCAT:
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8296 case ISN_EXECUTE:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8297 case ISN_FOR:
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
8298 case ISN_GETITEM:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
8299 case ISN_JUMP:
22633
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
8300 case ISN_LISTAPPEND:
21393
320581a133d9 patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents: 21391
diff changeset
8301 case ISN_LISTINDEX:
21828
af5db9b6d210 patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21826
diff changeset
8302 case ISN_LISTSLICE:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8303 case ISN_LOAD:
21399
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
8304 case ISN_LOADBDICT:
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
8305 case ISN_LOADGDICT:
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
8306 case ISN_LOADOUTER:
21399
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
8307 case ISN_LOADREG:
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
8308 case ISN_LOADTDICT:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8309 case ISN_LOADV:
21399
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
8310 case ISN_LOADWDICT:
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
8311 case ISN_LOCKCONST:
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
8312 case ISN_MEMBER:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8313 case ISN_NEGATENR:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8314 case ISN_NEWDICT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8315 case ISN_NEWLIST:
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
8316 case ISN_OPANY:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8317 case ISN_OPFLOAT:
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
8318 case ISN_OPNR:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8319 case ISN_PCALL:
19862
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19860
diff changeset
8320 case ISN_PCALL_END:
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
8321 case ISN_PUSHBOOL:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8322 case ISN_PUSHF:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8323 case ISN_PUSHNR:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8324 case ISN_PUSHSPEC:
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8325 case ISN_PUT:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8326 case ISN_RETURN:
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
8327 case ISN_SHUFFLE:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
8328 case ISN_SLICE:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8329 case ISN_STORE:
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
8330 case ISN_STOREINDEX:
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
8331 case ISN_STORENR:
20295
bc2c9ea94ec1 patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents: 20283
diff changeset
8332 case ISN_STOREOUTER:
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
8333 case ISN_STOREREG:
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
8334 case ISN_STOREV:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
8335 case ISN_STRINDEX:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
8336 case ISN_STRSLICE:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8337 case ISN_THROW:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8338 case ISN_TRY:
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
8339 case ISN_UNPACK:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8340 // nothing allocated
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8341 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8342 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8343 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8344
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8345 /*
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8346 * Free all instructions for "dfunc" except df_name.
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8347 */
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8348 static void
23360
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
8349 delete_def_function_contents(dfunc_T *dfunc, int mark_deleted)
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8350 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8351 int idx;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8352
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8353 ga_clear(&dfunc->df_def_args_isn);
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8354
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8355 if (dfunc->df_instr != NULL)
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8356 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8357 for (idx = 0; idx < dfunc->df_instr_count; ++idx)
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8358 delete_instr(dfunc->df_instr + idx);
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8359 VIM_CLEAR(dfunc->df_instr);
23360
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
8360 dfunc->df_instr = NULL;
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
8361 }
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
8362
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
8363 if (mark_deleted)
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
8364 dfunc->df_deleted = TRUE;
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
8365 if (dfunc->df_ufunc != NULL)
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
8366 dfunc->df_ufunc->uf_def_status = UF_NOT_COMPILED;
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8367 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8368
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8369 /*
20943
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
8370 * When a user function is deleted, clear the contents of any associated def
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8371 * function, unless another user function still uses it.
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8372 * The position in def_functions can be re-used.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8373 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8374 void
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8375 unlink_def_function(ufunc_T *ufunc)
20943
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
8376 {
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
8377 if (ufunc->uf_dfunc_idx > 0)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8378 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8379 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8380 + ufunc->uf_dfunc_idx;
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8381
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8382 if (--dfunc->df_refcount <= 0)
23360
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
8383 delete_def_function_contents(dfunc, TRUE);
20943
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
8384 ufunc->uf_def_status = UF_NOT_COMPILED;
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8385 ufunc->uf_dfunc_idx = 0;
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8386 if (dfunc->df_ufunc == ufunc)
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8387 dfunc->df_ufunc = NULL;
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8388 }
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8389 }
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8390
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8391 /*
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8392 * Used when a user function refers to an existing dfunc.
22324
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
8393 */
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
8394 void
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8395 link_def_function(ufunc_T *ufunc)
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8396 {
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8397 if (ufunc->uf_dfunc_idx > 0)
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8398 {
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8399 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8400 + ufunc->uf_dfunc_idx;
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8401
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8402 ++dfunc->df_refcount;
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8403 }
22324
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
8404 }
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
8405
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8406 #if defined(EXITFREE) || defined(PROTO)
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8407 /*
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8408 * Free all functions defined with ":def".
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8409 */
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8410 void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8411 free_def_functions(void)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8412 {
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8413 int idx;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8414
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8415 for (idx = 0; idx < def_functions.ga_len; ++idx)
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8416 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8417 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) + idx;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8418
23360
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
8419 delete_def_function_contents(dfunc, TRUE);
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8420 vim_free(dfunc->df_name);
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8421 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8422
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
8423 ga_clear(&def_functions);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8424 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8425 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8426
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8427
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8428 #endif // FEAT_EVAL