annotate src/vim9compile.c @ 24614:07b3d21a8b4b v8.2.2846

patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void Commit: https://github.com/vim/vim/commit/68db996b621b98066fb7ab7028ed5c6aaa3954a8 Author: Bram Moolenaar <Bram@vim.org> Date: Sun May 9 23:19:22 2021 +0200 patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void Problem: Vim9: "echo Func()" does not give an error for a function without a return value. Solution: Give an error. Be more specific about why a value is invalid.
author Bram Moolenaar <Bram@vim.org>
date Sun, 09 May 2021 23:30:05 +0200
parents cb031f421ece
children 4a4f64cdc798
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;
23723
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
47 int is_seen_skip_not; // a block was unconditionally executed
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
48 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
49 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
50 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
51 } ifscope_T;
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 * 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
55 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 typedef struct {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 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
58 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
59 } whilescope_T;
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 * 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
63 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 typedef struct {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 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
66 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
67 } forscope_T;
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 * 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
71 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 typedef struct {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 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
74 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
75 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
76 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
77 } tryscope_T;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 typedef enum {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 NO_SCOPE,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 IF_SCOPE,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 WHILE_SCOPE,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 FOR_SCOPE,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 TRY_SCOPE,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 BLOCK_SCOPE
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 } scopetype_T;
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 * 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
90 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 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
92 struct scope_S {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 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
94 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
95 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
96 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
97 union {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 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
99 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
100 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
101 tryscope_T se_try;
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
102 } se_u;
19181
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 * 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
107 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 typedef struct {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 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
110 type_T *lv_type;
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
111 int lv_idx; // index of the variable on the stack
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
112 int lv_from_outer; // nesting level, using ctx_outer scope
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
113 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
114 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
115 } lvar_T;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
117 // Destination for an assignment or ":unlet" with an index.
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
118 typedef enum {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
119 dest_local,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
120 dest_option,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
121 dest_env,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
122 dest_global,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
123 dest_buffer,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
124 dest_window,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
125 dest_tab,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
126 dest_vimvar,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
127 dest_script,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
128 dest_reg,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
129 dest_expr,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
130 } assign_dest_T;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
131
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
132 // Used by compile_lhs() to store information about the LHS of an assignment
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
133 // and one argument of ":unlet" with an index.
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
134 typedef struct {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
135 assign_dest_T lhs_dest; // type of destination
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
136
24512
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
137 char_u *lhs_name; // allocated name excluding the last
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
138 // "[expr]" or ".name".
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
139 size_t lhs_varlen; // length of the variable without
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
140 // "[expr]" or ".name"
24512
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
141 char_u *lhs_whole; // allocated name including the last
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
142 // "[expr]" or ".name" for :redir
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
143 size_t lhs_varlen_total; // length of the variable including
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
144 // any "[expr]" or ".name"
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
145 char_u *lhs_dest_end; // end of the destination, including
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
146 // "[expr]" or ".name".
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
147
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
148 int lhs_has_index; // has "[expr]" or ".name"
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
149
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
150 int lhs_new_local; // create new local variable
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
151 int lhs_opt_flags; // for when destination is an option
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
152 int lhs_vimvaridx; // for when destination is a v:var
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
153
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
154 lvar_T lhs_local_lvar; // used for existing local destination
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
155 lvar_T lhs_arg_lvar; // used for argument destination
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
156 lvar_T *lhs_lvar; // points to destination lvar
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
157 int lhs_scriptvar_sid;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
158 int lhs_scriptvar_idx;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
159
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
160 int lhs_has_type; // type was specified
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
161 type_T *lhs_type;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
162 type_T *lhs_member_type;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
163
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
164 int lhs_append; // used by ISN_REDIREND
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
165 } lhs_T;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
166
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 * 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
169 * 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
170 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 struct cctx_S {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 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
173 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
174 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
175 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
176
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
177 int ctx_profiling; // when TRUE generate ISN_PROF_START
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
178
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 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
180 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
181
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22369
diff changeset
182 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
183 // the function
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
184
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 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
186
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
187 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
188 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
189 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
190
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
191 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
192 // function
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
193 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
194
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 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
196 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
197
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
198 int ctx_has_cmdmod; // ISN_CMDMOD was generated
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
199
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
200 lhs_T ctx_redir_lhs; // LHS for ":redir => var", valid when
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
201 // lhs_name is not NULL
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 };
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203
23360
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
204 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
205
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 /*
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
207 * Lookup variable "name" in the local scope and return it in "lvar".
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
208 * "lvar->lv_from_outer" is incremented accordingly.
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
209 * 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
210 * 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
211 */
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
212 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
213 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
214 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 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
216 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
217
19392
5b6f420e7352 patch 8.2.0254: compiler warning for checking size_t to be negative
Bram Moolenaar <Bram@vim.org>
parents: 19388
diff changeset
218 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
219 return FAIL;
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
220
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
221 // 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
222 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
223 {
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
224 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
225 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
226 && 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
227 {
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
228 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
229 {
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
230 *lvar = *lvp;
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
231 lvar->lv_from_outer = 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
232 }
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
233 return OK;
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
234 }
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
235 }
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
236
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
237 // 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
238 if (cctx->ctx_outer != NULL)
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
239 {
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
240 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
241 {
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
242 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
243 {
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
244 cctx->ctx_outer_used = TRUE;
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
245 ++lvar->lv_from_outer;
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
246 }
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
247 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
248 }
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
249 }
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
250
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
251 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 /*
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
255 * 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
256 * 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
257 * 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
258 * 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
259 * 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
260 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 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
262 arg_exists(
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
263 char_u *name,
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
264 size_t len,
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
265 int *idxp,
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
266 type_T **type,
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
267 int *gen_load_outer,
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
268 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
269 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 int idx;
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
271 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
272
19392
5b6f420e7352 patch 8.2.0254: compiler warning for checking size_t to be negative
Bram Moolenaar <Bram@vim.org>
parents: 19388
diff changeset
273 if (len == 0)
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
274 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 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
276 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 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
278
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
279 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
280 {
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
281 if (idxp != NULL)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
282 {
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
283 // 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
284 // 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
285 *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
286 + STACK_FRAME_SIZE)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
287 + (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
288
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
289 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
290 *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
291 else
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
292 *type = &t_any;
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
293 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
294 return OK;
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
295 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
296 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
297
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
298 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
299 if (va_name != NULL
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
300 && 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
301 {
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
302 if (idxp != NULL)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
303 {
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
304 // 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
305 *idxp = -STACK_FRAME_SIZE - 1;
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
306 *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
307 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
308 return OK;
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
309 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
310
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
311 if (cctx->ctx_outer != NULL)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
312 {
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
313 // 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
314 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
315 == OK)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
316 {
23923
be36288235af patch 8.2.2504: Vim9: crash when using an argument from a closure
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
317 if (gen_load_outer != NULL)
be36288235af patch 8.2.2504: Vim9: crash when using an argument from a closure
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
318 ++*gen_load_outer;
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
319 return OK;
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
320 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
321 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
322
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
323 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 /*
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
327 * 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
328 * 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
329 * "cctx" is NULL at the script level.
24061
d6489b4eb14e patch 8.2.2572: Vim9: crash when getting the types for a legacy function
Bram Moolenaar <Bram@vim.org>
parents: 24033
diff changeset
330 * If "len" is <= 0 "name" must be NUL terminated.
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
331 * 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
332 */
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
333 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
334 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
335 {
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
336 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
337 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
338 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
339 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
340 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
341
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
342 // 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
343 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
344 {
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
345 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
346 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
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 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
349 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
350 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
351 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
352 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
353
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
354 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
355 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
356 // 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
357 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
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 // 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
360 // 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
361 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
362 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
363 {
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
364 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
365
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
366 // 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
367 // 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
368 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
369 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
370 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
371 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
372 }
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
373
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
374 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
375 }
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
376
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
377 /*
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 23199
diff changeset
378 * 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
379 */
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
380 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
381 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
382 {
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
383 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
384 }
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
385
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
386 /*
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 * Lookup a variable (without s: prefix) in the current script.
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
388 * "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
389 * 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
390 */
24388
72f3e40f046c patch 8.2.2734: Vim9: cannot use legacy script-local var from :def function
Bram Moolenaar <Bram@vim.org>
parents: 24379
diff changeset
391 static int
72f3e40f046c patch 8.2.2734: Vim9: cannot use legacy script-local var from :def function
Bram Moolenaar <Bram@vim.org>
parents: 24379
diff changeset
392 script_var_exists(char_u *name, size_t len, cctx_T *cctx)
72f3e40f046c patch 8.2.2734: Vim9: cannot use legacy script-local var from :def function
Bram Moolenaar <Bram@vim.org>
parents: 24379
diff changeset
393 {
22381
6fe9536694ff patch 8.2.1739: Vim9: crash when compiling a manually defined function
Bram Moolenaar <Bram@vim.org>
parents: 22371
diff changeset
394 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
395 return FAIL;
24388
72f3e40f046c patch 8.2.2734: Vim9: cannot use legacy script-local var from :def function
Bram Moolenaar <Bram@vim.org>
parents: 24379
diff changeset
396 if (script_is_vim9())
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
397 {
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
398 // 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
399 // defined.
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
400 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
401 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
402 }
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
403 else
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
404 {
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
405 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
406 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
407 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
408
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
409 // 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
410 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
411 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
412 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
413 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
414 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
415 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
416 }
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
417
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
418 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420
19623
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
421 /*
23966
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
422 * Return TRUE if "name" is a local variable, argument, script variable or
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
423 * imported.
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
424 */
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
425 static int
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
426 variable_exists(char_u *name, size_t len, cctx_T *cctx)
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
427 {
24033
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
428 return (cctx != NULL
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
429 && (lookup_local(name, len, NULL, cctx) == OK
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
430 || arg_exists(name, len, NULL, NULL, NULL, cctx) == OK))
24388
72f3e40f046c patch 8.2.2734: Vim9: cannot use legacy script-local var from :def function
Bram Moolenaar <Bram@vim.org>
parents: 24379
diff changeset
431 || script_var_exists(name, len, cctx) == OK
23966
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
432 || find_imported(name, len, cctx) != NULL;
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
433 }
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
434
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
435 /*
24067
780dec2ffa6b patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
436 * Return TRUE if "name" is a local variable, argument, script variable,
780dec2ffa6b patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
437 * imported or function.
780dec2ffa6b patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
438 */
780dec2ffa6b patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
439 static int
24124
f4061617c438 patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents: 24116
diff changeset
440 item_exists(char_u *name, size_t len, int cmd UNUSED, cctx_T *cctx)
24067
780dec2ffa6b patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
441 {
780dec2ffa6b patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
442 int is_global;
24124
f4061617c438 patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents: 24116
diff changeset
443 char_u *p;
24067
780dec2ffa6b patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
444
780dec2ffa6b patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
445 if (variable_exists(name, len, cctx))
780dec2ffa6b patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
446 return TRUE;
780dec2ffa6b patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
447
24124
f4061617c438 patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents: 24116
diff changeset
448 // This is similar to what is in lookup_scriptitem():
f4061617c438 patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents: 24116
diff changeset
449 // Find a function, so that a following "->" works.
f4061617c438 patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents: 24116
diff changeset
450 // Require "(" or "->" to follow, "Cmd" is a user command while "Cmd()" is
f4061617c438 patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents: 24116
diff changeset
451 // a function call.
f4061617c438 patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents: 24116
diff changeset
452 p = skipwhite(name + len);
f4061617c438 patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents: 24116
diff changeset
453
f4061617c438 patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents: 24116
diff changeset
454 if (name[len] == '(' || (p[0] == '-' && p[1] == '>'))
f4061617c438 patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents: 24116
diff changeset
455 {
f4061617c438 patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents: 24116
diff changeset
456 // Do not check for an internal function, since it might also be a
f4061617c438 patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents: 24116
diff changeset
457 // valid command, such as ":split" versuse "split()".
f4061617c438 patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents: 24116
diff changeset
458 // Skip "g:" before a function name.
f4061617c438 patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents: 24116
diff changeset
459 is_global = (name[0] == 'g' && name[1] == ':');
f4061617c438 patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents: 24116
diff changeset
460 return find_func(is_global ? name + 2 : name, is_global, cctx) != NULL;
f4061617c438 patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents: 24116
diff changeset
461 }
f4061617c438 patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents: 24116
diff changeset
462 return FALSE;
24067
780dec2ffa6b patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
463 }
780dec2ffa6b patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
464
780dec2ffa6b patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
465 /*
19623
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
466 * 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
467 * 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
468 * Does not check the global namespace.
24033
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
469 * If "is_arg" is TRUE the error message is for an argument name.
19623
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
470 * 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
471 */
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
472 int
24033
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
473 check_defined(char_u *p, size_t len, cctx_T *cctx, int is_arg)
19623
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
474 {
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
475 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
476 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
477
24420
e0fa539a9b34 patch 8.2.2750: Vim9: error for using underscore in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24408
diff changeset
478 // underscore argument is OK
e0fa539a9b34 patch 8.2.2750: Vim9: error for using underscore in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24408
diff changeset
479 if (len == 1 && *p == '_')
e0fa539a9b34 patch 8.2.2750: Vim9: error for using underscore in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24408
diff changeset
480 return OK;
e0fa539a9b34 patch 8.2.2750: Vim9: error for using underscore in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24408
diff changeset
481
24388
72f3e40f046c patch 8.2.2734: Vim9: cannot use legacy script-local var from :def function
Bram Moolenaar <Bram@vim.org>
parents: 24379
diff changeset
482 if (script_var_exists(p, len, cctx) == OK)
24033
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
483 {
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
484 if (is_arg)
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
485 semsg(_(e_argument_already_declared_in_script_str), p);
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
486 else
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
487 semsg(_(e_variable_already_declared_in_script_str), p);
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
488 return FAIL;
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
489 }
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
490
21604
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
491 p[len] = NUL;
24033
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
492 if ((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
493 && (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
494 || 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
495 || 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
496 || (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
497 {
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
498 // 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
499 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
500 || (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
501 {
24033
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
502 if (is_arg)
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
503 semsg(_(e_argument_name_shadows_existing_variable_str), p);
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
504 else
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
505 semsg(_(e_name_already_defined_str), p);
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
506 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
507 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
508 }
19623
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
509 }
21604
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
510 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
511 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
512 }
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
513
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
514
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 /////////////////////////////////////////////////////////////////////
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 // 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
517
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
518 #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
519 #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
520
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 * 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
523 * 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
524 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 static isn_T *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 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
527 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 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
529 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
531 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
532 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
533 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 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
535 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
536 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
537 ++instr->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 return isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 * 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
544 * "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
545 * 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
546 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 static isn_T *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 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
549 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 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
551
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
552 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
553 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
554 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
555 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 * 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
559 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 static isn_T *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 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
562 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 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
565
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 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
567 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 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
570 return NULL;
21473
8bcd1ee2630b patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
571 ((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
572 ++stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 return isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 * 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
579 * 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
580 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 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
583 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 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
585 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
586 garray_T *stack = &cctx->ctx_type_stack;
23576
4cd173b3d572 patch 8.2.2330: Vim9: crash when using :trow in a not executed block
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
587 type_T **type;
4cd173b3d572 patch 8.2.2330: Vim9: crash when using :trow in a not executed block
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
588
4cd173b3d572 patch 8.2.2330: Vim9: crash when using :trow in a not executed block
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
589 RETURN_OK_IF_SKIP(cctx);
4cd173b3d572 patch 8.2.2330: Vim9: crash when using :trow in a not executed block
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
590 type = ((type_T **)stack->ga_data) + stack->ga_len + offset;
21771
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
591 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
592 {
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
593 // 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
594 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
595
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
596 // 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
597 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
598 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
599 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
600 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
601 break;
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
602
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
603 // 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
604 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
605 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
606 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
607 break;
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
608
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
609 // 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
610 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
611 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
612 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
613 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
614 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
615 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
616 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
617 case VAR_CHANNEL:
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
618 case VAR_INSTR:
21771
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
619 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
620 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
621 }
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
622
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 *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
624 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
625 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 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
627
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 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
633 {
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
634 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
635 && (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
636 || 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
637 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 if (*op == '+')
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
639 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
640 else
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
641 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
642 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
647 static int
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
648 generate_add_instr(
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
649 cctx_T *cctx,
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
650 vartype_T vartype,
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
651 type_T *type1,
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
652 type_T *type2)
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
653 {
23199
59f31d2eb4cf patch 8.2.2145: Vim9: concatenating lists does not adjust type of result
Bram Moolenaar <Bram@vim.org>
parents: 23195
diff changeset
654 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
655 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
656 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
657 : 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
658 : 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
659 #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
660 : 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
661 #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
662 : ISN_OPANY, 1);
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
663
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
664 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
665 && type1->tt_type != VAR_ANY
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
666 && type2->tt_type != VAR_ANY
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
667 && check_number_or_float(
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
668 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
669 return FAIL;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
670
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
671 if (isn != NULL)
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
672 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
673
59f31d2eb4cf patch 8.2.2145: Vim9: concatenating lists does not adjust type of result
Bram Moolenaar <Bram@vim.org>
parents: 23195
diff changeset
674 // 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
675 // 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
676 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
677 && 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
678 && 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
679 (((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
680
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
681 return isn == NULL ? FAIL : OK;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
682 }
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
683
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
684 /*
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
685 * 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
686 * "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
687 * 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
688 */
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
689 static vartype_T
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
690 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
691 {
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
692 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
693 && (type1->tt_type == VAR_NUMBER
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
694 || type1->tt_type == VAR_LIST
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
695 #ifdef FEAT_FLOAT
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
696 || type1->tt_type == VAR_FLOAT
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
697 #endif
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
698 || type1->tt_type == VAR_BLOB))
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
699 return type1->tt_type;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
700 return VAR_ANY;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
701 }
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
702
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 * 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
705 * 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
706 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 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
709 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 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
711 type_T *type1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 type_T *type2;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 vartype_T vartype;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
716 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
717
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
718 // 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
719 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
720 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
721 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
722
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 switch (*op)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 {
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
725 case '+':
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
726 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
727 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 case '-':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 case '*':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 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
733 op) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 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
736 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
737 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 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
739 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
740 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 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
743 if (isn != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 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
745 ? 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
746 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
748 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
749 && 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
750 || (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
751 && 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
752 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
753 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
754 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 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
757 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
758 if (isn != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 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
760 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 // 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
764 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
765 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 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
767
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 // 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
770 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
771 && (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
772 type = &t_float;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 ((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
775 }
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 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 }
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 /*
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
781 * 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
782 * 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
783 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
784 static isntype_T
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
785 get_compare_isn(exprtype_T exprtype, 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
786 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 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
788
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
789 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
790 type1 = VAR_ANY;
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
791 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
792 type2 = VAR_ANY;
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
793
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 if (type1 == type2)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 switch (type1)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 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
799 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
800 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
801 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
802 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
803 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
804 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
805 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
806 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
807 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
808 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 }
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
810 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
811 || ((type1 == VAR_NUMBER || type1 == VAR_FLOAT)
24067
780dec2ffa6b patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24061
diff changeset
812 && (type2 == VAR_NUMBER || type2 == VAR_FLOAT)))
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 isntype = ISN_COMPAREANY;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
815 if ((exprtype == EXPR_IS || exprtype == EXPR_ISNOT)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 && (isntype == ISN_COMPAREBOOL
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 || isntype == ISN_COMPARESPECIAL
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 || isntype == ISN_COMPARENR
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 || isntype == ISN_COMPAREFLOAT))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
821 semsg(_(e_cannot_use_str_with_str),
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
822 exprtype == 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
823 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
824 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 if (isntype == ISN_DROP
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
826 || ((exprtype != EXPR_EQUAL && exprtype != EXPR_NEQUAL
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 && (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
828 || type2 == VAR_BOOL || type2 == VAR_SPECIAL)))
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
829 || ((exprtype != EXPR_EQUAL && exprtype != EXPR_NEQUAL
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
830 && exprtype != EXPR_IS && exprtype != EXPR_ISNOT
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 && (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
832 || 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
833 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
834 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
835 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
836 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
837 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
838 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
839 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
840
21251
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
841 int
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
842 check_compare_types(exprtype_T type, typval_T *tv1, typval_T *tv2)
21251
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
843 {
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
844 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
845 return FAIL;
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
846 return OK;
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
847 }
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
848
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
849 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
850 * 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
851 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
852 static int
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
853 generate_COMPARE(cctx_T *cctx, exprtype_T exprtype, int ic)
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
854 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
855 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
856 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
857 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
858 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
859 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
860
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
861 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
862
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
863 // 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
864 // 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
865 // checking.
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
866 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
867 type2 = ((type_T **)stack->ga_data)[stack->ga_len - 1]->tt_type;
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
868 isntype = get_compare_isn(exprtype, type1, 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
869 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
870 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 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
873 return FAIL;
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
874 isn->isn_arg.op.op_type = exprtype;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 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
876
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 // 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
878 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
879 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 --stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 ((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
882 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 * 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
889 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 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
892 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 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
895
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
896 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
897 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
898 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 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
900
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 // type becomes bool
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 ((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
903
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
907 /*
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
908 * 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
909 */
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
910 static int
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
911 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
912 {
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
913 isn_T *isn;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
914 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
915
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
916 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
917 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
918 return FAIL;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
919
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
920 // type becomes bool
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
921 ((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
922
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
923 return OK;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
924 }
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
925
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 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
927 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
928 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
929 type_T *expected,
23691
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
930 int offset,
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
931 int argidx)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 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
935
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
936 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
937 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
938 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
939 isn->isn_arg.type.ct_type = alloc_type(expected);
23697
19073a768852 patch 8.2.2390: Vim9: using positive offset is unexpected
Bram Moolenaar <Bram@vim.org>
parents: 23695
diff changeset
940 isn->isn_arg.type.ct_off = (int8_T)offset;
19073a768852 patch 8.2.2390: Vim9: using positive offset is unexpected
Bram Moolenaar <Bram@vim.org>
parents: 23695
diff changeset
941 isn->isn_arg.type.ct_arg_idx = (int8_T)argidx;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942
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
943 // 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
944 ((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
945
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948
23458
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
949 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
950 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
951 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
952 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
953 {
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
954 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
955
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
956 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
957 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
958 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
959 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
960 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
961 }
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
962
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 /*
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
964 * 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
965 * 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
966 */
22898
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22860
diff changeset
967 int
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
968 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
969 {
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
970 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
971 || 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
972 || (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
973 && (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
974 || expected->tt_type == VAR_PARTIAL)
23531
f39a18a42aed patch 8.2.2308: Vim9: no error when assigning lambda to funcref
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
975 && (actual->tt_member == &t_any || actual->tt_argcount < 0)
f39a18a42aed patch 8.2.2308: Vim9: no error when assigning lambda to funcref
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
976 && ((actual->tt_member == &t_void)
f39a18a42aed patch 8.2.2308: Vim9: no error when assigning lambda to funcref
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
977 == (expected->tt_member == &t_void))))
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
978 return TRUE;
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
979 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
980 && 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
981 // 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
982 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
983 return FALSE;
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
984 }
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
985
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
986 /*
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
987 * 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
988 * - "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
989 * - "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
990 * - return FAIL.
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
991 * 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
992 * generate a TYPECHECK.
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
993 */
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
994 int
21265
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21255
diff changeset
995 need_type(
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21255
diff changeset
996 type_T *actual,
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21255
diff changeset
997 type_T *expected,
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21255
diff changeset
998 int offset,
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
999 int arg_idx,
21265
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21255
diff changeset
1000 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
1001 int silent,
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
1002 int actual_is_const)
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
1003 {
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
1004 where_T where;
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
1005
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
1006 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
1007 && (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
1008 {
d835f2fdfcfc patch 8.2.1647: Vim9: result of expression with && and || is not a bool
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
1009 // 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
1010 // 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
1011 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
1012 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
1013 }
d835f2fdfcfc patch 8.2.1647: Vim9: result of expression with && and || is not a bool
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
1014
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
1015 where.wt_index = arg_idx;
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
1016 where.wt_variable = FALSE;
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
1017 if (check_type(expected, actual, FALSE, where) == OK)
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
1018 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
1019
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
1020 // 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
1021 // 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
1022 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
1023 {
23691
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
1024 generate_TYPECHECK(cctx, expected, offset, arg_idx);
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
1025 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
1026 }
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
1027
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
1028 if (!silent)
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
1029 arg_type_mismatch(expected, actual, arg_idx);
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
1030 return FAIL;
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
1031 }
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
1032
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
1033 /*
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
1034 * 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
1035 * 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
1036 */
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
1037 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
1038 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
1039 {
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
1040 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
1041 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
1042
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
1043 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
1044 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
1045 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
1046
24430
fe71212fd202 patch 8.2.2755: Vim9: no error for using a number in a condition
Bram Moolenaar <Bram@vim.org>
parents: 24426
diff changeset
1047 if (type == &t_any || type == &t_number || type == &t_number_bool)
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
1048 // 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
1049 // 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
1050 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
1051
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
1052 return need_type(type, &t_bool, -1, 0, cctx, FALSE, FALSE);
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
1053 }
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
1054
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
1055 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 * 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
1057 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 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
1060 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 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
1062 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
1063
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1064 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
1065 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
1066 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 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
1068
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
1069 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
1070 // 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
1071 ((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
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 * 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
1077 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 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
1080 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1083 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
1084 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
1085 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 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
1087
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 * 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
1093 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 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
1096 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1099 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
1100 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
1101 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 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
1103
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 * 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
1110 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 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
1113 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1116 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
1117 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
1118 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 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
1120
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 * 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
1127 * Consumes "str".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 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
1131 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133
23473
ad83c0ff34c0 patch 8.2.2279: Vim9: memory leak with catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23458
diff changeset
1134 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
1135 {
ad83c0ff34c0 patch 8.2.2279: Vim9: memory leak with catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23458
diff changeset
1136 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
1137 return OK;
ad83c0ff34c0 patch 8.2.2279: Vim9: memory leak with catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23458
diff changeset
1138 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 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
1140 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 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
1142
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 /*
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1147 * 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
1148 * Consumes "channel".
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1149 */
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1150 static int
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1151 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
1152 {
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1153 isn_T *isn;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1154
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1155 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
1156 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
1157 return FAIL;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1158 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
1159
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1160 return OK;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1161 }
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1162
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1163 /*
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1164 * 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
1165 * Consumes "job".
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1166 */
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1167 static int
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1168 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
1169 {
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1170 isn_T *isn;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1171
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1172 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
1173 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
1174 return FAIL;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1175 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
1176
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1177 return OK;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1178 }
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1179
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1180 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 * 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
1182 * Consumes "blob".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 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
1186 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1189 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
1190 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
1191 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 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
1193
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 return OK;
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
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 /*
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1198 * 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
1199 * Consumes "name".
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1200 */
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1201 static int
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
1202 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
1203 {
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1204 isn_T *isn;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1205
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1206 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
1207 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
1208 return FAIL;
21473
8bcd1ee2630b patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
1209 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
1210
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1211 return OK;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1212 }
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1213
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1214 /*
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1215 * 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
1216 */
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1217 static int
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1218 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
1219 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1220 isn_T *isn;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1221 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
1222 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
1223 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
1224
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1225 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
1226
21421
0f0fee4122d3 patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents: 21411
diff changeset
1227 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
1228 {
0f0fee4122d3 patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents: 21411
diff changeset
1229 // 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
1230 emsg(_(e_listreq));
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1231 return FAIL;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1232 }
21421
0f0fee4122d3 patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents: 21411
diff changeset
1233 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
1234 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
1235 return FAIL;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1236 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
1237
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1238 // 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
1239 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
1240 return FAIL;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1241 ((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
1242 ++stack->ga_len;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1243 return OK;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1244 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1245
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1246 /*
20871
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1247 * 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
1248 */
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1249 static int
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1250 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
1251 {
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1252 isn_T *isn;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1253
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1254 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
1255 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
1256 return FAIL;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1257 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
1258 return OK;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1259 }
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1260
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1261 /*
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1262 * 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
1263 */
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1264 static int
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1265 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
1266 {
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1267 isn_T *isn;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1268
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1269 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
1270
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1271 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
1272 return FAIL;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1273 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
1274 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
1275
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1276 return OK;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1277 }
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1278
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1279 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 * 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
1281 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283 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
1284 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1287 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
1288 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
1289 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290 if (name != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 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
1292 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 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
1294
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1296 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 /*
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1299 * Generate an ISN_STOREOUTER instruction.
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1300 */
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1301 static int
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1302 generate_STOREOUTER(cctx_T *cctx, int idx, int level)
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1303 {
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1304 isn_T *isn;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1305
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1306 RETURN_OK_IF_SKIP(cctx);
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1307 if ((isn = generate_instr_drop(cctx, ISN_STOREOUTER, 1)) == NULL)
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1308 return FAIL;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1309 isn->isn_arg.outer.outer_idx = idx;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1310 isn->isn_arg.outer.outer_depth = level;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1311
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1312 return OK;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1313 }
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1314
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1315 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 * 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
1317 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1318 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1319 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
1320 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1321 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1322
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1323 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
1324 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
1325 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
1326 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
1327 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
1328
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1329 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 * 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
1334 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 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
1337 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1338 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1339
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1340 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
1341 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
1342 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1343 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
1344 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
1345
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1346 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1347 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1349 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1350 * 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
1351 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1353 generate_LOAD(
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 cctx_T *cctx,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 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
1356 int idx,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 char_u *name,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 type_T *type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1359 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1360 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1362 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
1363 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
1364 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365 if (name != NULL)
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.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
1367 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1368 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
1369
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1370 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373 /*
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1374 * Generate an ISN_LOADOUTER instruction
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1375 */
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1376 static int
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1377 generate_LOADOUTER(
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1378 cctx_T *cctx,
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1379 int idx,
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1380 int nesting,
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1381 type_T *type)
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1382 {
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1383 isn_T *isn;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1384
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1385 RETURN_OK_IF_SKIP(cctx);
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1386 if ((isn = generate_instr_type(cctx, ISN_LOADOUTER, type)) == NULL)
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1387 return FAIL;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1388 isn->isn_arg.outer.outer_idx = idx;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1389 isn->isn_arg.outer.outer_depth = nesting;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1390
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1391 return OK;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1392 }
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1393
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1394 /*
19960
3c11b9f6fa03 patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1395 * 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
1396 */
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1397 static int
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1398 generate_LOADV(
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1399 cctx_T *cctx,
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1400 char_u *name,
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1401 int error)
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1402 {
19960
3c11b9f6fa03 patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1403 int di_flags;
3c11b9f6fa03 patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1404 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
1405 type_T *type;
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1406
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1407 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
1408 if (vidx < 0)
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1409 {
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1410 if (error)
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
1411 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
1412 return FAIL;
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1413 }
21443
66386ca8a69f patch 8.2.1272: Vim9: type not checked if declaration also assigns value
Bram Moolenaar <Bram@vim.org>
parents: 21441
diff changeset
1414 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
1415
3c11b9f6fa03 patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1416 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
1417 }
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1418
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1419 /*
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1420 * Generate an ISN_UNLET instruction.
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1421 */
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1422 static int
20099
058b41f85bcb patch 8.2.0605: Vim9: cannot unlet an environment variable
Bram Moolenaar <Bram@vim.org>
parents: 20091
diff changeset
1423 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
1424 {
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1425 isn_T *isn;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1426
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1427 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
1428 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
1429 return FAIL;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1430 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
1431 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
1432
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1433 return OK;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1434 }
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1435
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1436 /*
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1437 * 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
1438 */
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1439 static int
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1440 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
1441 {
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1442 isn_T *isn;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1443
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1444 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
1445 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
1446 return FAIL;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1447 return OK;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1448 }
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1449
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1450 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1451 * 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
1452 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1453 static int
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1454 generate_OLDSCRIPT(
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455 cctx_T *cctx,
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1456 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
1457 char_u *name,
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1458 int sid,
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1459 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
1460 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1461 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1462
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1463 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
1464 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
1465 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
1466 else
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1467 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
1468 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
1469 return FAIL;
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1470 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
1471 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
1472
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1475
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1476 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477 * 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
1478 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479 static int
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1480 generate_VIM9SCRIPT(
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481 cctx_T *cctx,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1482 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
1483 int sid,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1484 int idx,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1485 type_T *type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1486 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1487 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
1488 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
1489 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
1490
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1491 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
1492 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
1493 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
1494 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1495 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
1496 if (isn == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1497 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
1498
e8eb4fd44902 patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents: 23318
diff changeset
1499 // 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
1500 // 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
1501 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
1502 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
1503 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
1504 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
1505 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
1506 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
1507 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
1508 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
1509 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 }
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513 * 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
1514 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1515 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1516 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
1517 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1518 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1519 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
1520 type_T *type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521 type_T *member;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1523 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
1524 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
1525 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526 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
1527
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
1528 // 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
1529 if (count == 0)
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1530 member = &t_void;
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1531 else
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1532 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
1533 ((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
1534 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
1535 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
1536
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537 // 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
1538 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
1539
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540 // 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
1541 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
1542 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1543 ((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
1544 ++stack->ga_len;
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 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1548
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1549 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 * 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
1551 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1553 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
1554 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1556 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
1557 type_T *type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558 type_T *member;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1560 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
1561 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
1562 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1563 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
1564
22021
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1565 if (count == 0)
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1566 member = &t_void;
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1567 else
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1568 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
1569 ((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
1570 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
1571 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
1572
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1573 // 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
1574 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
1575
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576 // 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
1577 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
1578 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1579 ((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
1580 ++stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1582 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1583 }
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1586 * 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
1587 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1588 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
1589 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
1590 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1591 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1592 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
1593
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1594 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
1595 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
1596 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
1597 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
1598 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
1599
24158
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
1600 // If the referenced function is a closure, it may use items further up in
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1601 // the nested context, including this one.
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1602 if (ufunc->uf_flags & FC_CLOSURE)
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1603 cctx->ctx_ufunc->uf_flags |= FC_CLOSURE;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1604
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1605 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
1606 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
1607 ((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
1608 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
1609 ++stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1610
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1611 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1612 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1613
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1614 /*
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1615 * 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
1616 * "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
1617 * consumed.
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1618 */
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1619 static int
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1620 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
1621 {
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1622 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
1623
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1624 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
1625 {
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1626 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
1627 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
1628 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
1629 }
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1630 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
1631 {
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1632 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
1633 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
1634 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
1635 }
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1636 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
1637 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
1638
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1639 return OK;
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1640 }
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1641
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1642 /*
22973
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1643 * 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
1644 */
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1645 static int
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1646 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
1647 {
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1648 isn_T *isn;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1649
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1650 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
1651 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
1652 return FAIL;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1653 if (len > 0)
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1654 {
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1655 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
1656 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
1657 return FAIL;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1658 }
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1659 return OK;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1660 }
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1661
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1662 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1663 * 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
1664 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1665 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1666 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
1667 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1668 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669 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
1670
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1671 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
1672 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
1673 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1674 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
1675 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
1676
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677 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
1678 --stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1679
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1680 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1681 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1682
24272
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1683 /*
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1684 * Generate an ISN_JUMP_IF_ARG_SET instruction.
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1685 */
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1686 static int
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1687 generate_JUMP_IF_ARG_SET(cctx_T *cctx, int arg_off)
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1688 {
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1689 isn_T *isn;
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1690
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1691 RETURN_OK_IF_SKIP(cctx);
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1692 if ((isn = generate_instr(cctx, ISN_JUMP_IF_ARG_SET)) == NULL)
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1693 return FAIL;
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1694 isn->isn_arg.jumparg.jump_arg_off = arg_off;
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1695 // jump_where is set later
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1696 return OK;
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1697 }
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1698
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1699 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1700 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
1701 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1702 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1703 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
1704
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1705 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
1706 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
1707 return FAIL;
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.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
1709
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1710 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
1711 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1712 // 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
1713 ((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
1714 ++stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1715
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1716 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1717 }
23927
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1718 /*
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1719 * Generate an ISN_TRYCONT instruction.
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1720 */
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1721 static int
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1722 generate_TRYCONT(cctx_T *cctx, int levels, int where)
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1723 {
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1724 isn_T *isn;
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1725
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1726 RETURN_OK_IF_SKIP(cctx);
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1727 if ((isn = generate_instr(cctx, ISN_TRYCONT)) == NULL)
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1728 return FAIL;
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1729 isn->isn_arg.trycont.tct_levels = levels;
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1730 isn->isn_arg.trycont.tct_where = where;
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1731
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1732 return OK;
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1733 }
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1734
19181
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1737 * 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
1738 * "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
1739 * 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
1740 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1741 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
1742 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
1743 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1744 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1745 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
1746 int argoff;
22671
ad54acb1bf2c patch 8.2.1884: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents: 22667
diff changeset
1747 type_T **argtypes = NULL;
23565
34aa2907082a patch 8.2.2325: Vim9: crash if map() changes the item type
Bram Moolenaar <Bram@vim.org>
parents: 23561
diff changeset
1748 type_T *maptype = NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1749
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1750 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
1751 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
1752 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
1753 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1754
21232
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
1755 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
1756 {
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
1757 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
1758 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
1759 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
1760 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
1761 }
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
1762
22663
0f90c15a4a28 patch 8.2.1880: Vim9: asan complains about adding zero to NULL
Bram Moolenaar <Bram@vim.org>
parents: 22661
diff changeset
1763 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
1764 {
0f90c15a4a28 patch 8.2.1880: Vim9: asan complains about adding zero to NULL
Bram Moolenaar <Bram@vim.org>
parents: 22661
diff changeset
1765 // 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
1766 argtypes = ((type_T **)stack->ga_data) + stack->ga_len - argcount;
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
1767 if (internal_func_check_arg_types(argtypes, func_idx, argcount,
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
1768 cctx) == 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
1769 return FAIL;
23565
34aa2907082a patch 8.2.2325: Vim9: crash if map() changes the item type
Bram Moolenaar <Bram@vim.org>
parents: 23561
diff changeset
1770 if (internal_func_is_map(func_idx))
34aa2907082a patch 8.2.2325: Vim9: crash if map() changes the item type
Bram Moolenaar <Bram@vim.org>
parents: 23561
diff changeset
1771 maptype = *argtypes;
22663
0f90c15a4a28 patch 8.2.1880: Vim9: asan complains about adding zero to NULL
Bram Moolenaar <Bram@vim.org>
parents: 22661
diff changeset
1772 }
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22639
diff changeset
1773
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1774 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
1775 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1776 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
1777 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
1778
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22639
diff changeset
1779 // 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
1780 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
1781 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
1782 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1783 ((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
1784 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
1785 ++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
1786
23565
34aa2907082a patch 8.2.2325: Vim9: crash if map() changes the item type
Bram Moolenaar <Bram@vim.org>
parents: 23561
diff changeset
1787 if (maptype != NULL && maptype->tt_member != NULL
34aa2907082a patch 8.2.2325: Vim9: crash if map() changes the item type
Bram Moolenaar <Bram@vim.org>
parents: 23561
diff changeset
1788 && maptype->tt_member != &t_any)
34aa2907082a patch 8.2.2325: Vim9: crash if map() changes the item type
Bram Moolenaar <Bram@vim.org>
parents: 23561
diff changeset
1789 // Check that map() didn't change the item types.
23691
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
1790 generate_TYPECHECK(cctx, maptype, -1, 1);
23565
34aa2907082a patch 8.2.2325: Vim9: crash if map() changes the item type
Bram Moolenaar <Bram@vim.org>
parents: 23561
diff changeset
1791
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1792 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1793 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1794
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1795 /*
22633
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1796 * 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
1797 * 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
1798 */
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1799 static int
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1800 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
1801 {
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1802 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
1803 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
1804 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
1805 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
1806
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1807 // 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
1808 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
1809 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
1810 expected = list_type->tt_member;
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
1811 if (need_type(item_type, expected, -1, 0, cctx, FALSE, FALSE) == FAIL)
22633
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1812 return FAIL;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1813
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1814 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
1815 return FAIL;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1816
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1817 --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
1818 return OK;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1819 }
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1820
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1821 /*
22637
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1822 * 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
1823 * 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
1824 */
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1825 static int
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1826 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
1827 {
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1828 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
1829 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
1830
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1831 // 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
1832 item_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
1833 if (need_type(item_type, &t_number, -1, 0, cctx, FALSE, FALSE) == FAIL)
22637
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1834 return FAIL;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1835
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1836 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
1837 return FAIL;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1838
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1839 --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
1840 return OK;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1841 }
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1842
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1843 /*
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1844 * Return TRUE if "ufunc" should be compiled, taking into account whether
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1845 * "profile" indicates profiling is to be done.
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1846 */
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1847 int
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
1848 func_needs_compiling(ufunc_T *ufunc, int profile UNUSED)
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1849 {
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1850 switch (ufunc->uf_def_status)
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1851 {
24404
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
1852 case UF_TO_BE_COMPILED:
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
1853 return TRUE;
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
1854
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1855 case UF_COMPILED:
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1856 {
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
1857 #ifdef FEAT_PROFILE
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1858 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1859 + ufunc->uf_dfunc_idx;
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1860
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1861 return profile ? dfunc->df_instr_prof == NULL
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1862 : dfunc->df_instr == NULL;
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
1863 #else
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
1864 break;
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
1865 #endif
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
1866 }
24404
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
1867
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
1868 case UF_NOT_COMPILED:
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
1869 case UF_COMPILE_ERROR:
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
1870 case UF_COMPILING:
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
1871 break;
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
1872 }
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
1873 return FALSE;
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1874 }
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1875
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1876 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1877 * 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
1878 * 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
1879 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1880 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
1881 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
1882 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1883 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1884 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
1885 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
1886 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
1887
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1888 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
1889 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
1890 {
22318
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22292
diff changeset
1891 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
1892 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1893 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1894 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
1895 {
22318
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22292
diff changeset
1896 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
1897 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1898 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1899
24404
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
1900 if (ufunc->uf_def_status != UF_NOT_COMPILED
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
1901 && ufunc->uf_def_status != UF_COMPILE_ERROR)
19944
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1902 {
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1903 int i;
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1904
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1905 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
1906 {
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1907 type_T *expected;
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1908 type_T *actual;
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1909
24272
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1910 actual = ((type_T **)stack->ga_data)[stack->ga_len - argcount + i];
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1911 if (actual == &t_special
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1912 && i >= regular_args - ufunc->uf_def_args.ga_len)
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1913 {
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1914 // assume v:none used for default argument value
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1915 continue;
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1916 }
19944
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1917 if (i < regular_args)
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1918 {
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1919 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
1920 continue;
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1921 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
1922 }
24400
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24390
diff changeset
1923 else if (ufunc->uf_va_type == NULL
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24390
diff changeset
1924 || ufunc->uf_va_type == &t_list_any)
22292
3515f341e8ac patch 8.2.1695: Vim9: crash when using varargs type "any"
Bram Moolenaar <Bram@vim.org>
parents: 22284
diff changeset
1925 // 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
1926 expected = &t_any;
19944
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1927 else
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1928 expected = ufunc->uf_va_type->tt_member;
23691
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
1929 if (need_type(actual, expected, -argcount + i, i + 1, cctx,
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
1930 TRUE, FALSE) == FAIL)
19944
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1931 {
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1932 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
1933 return FAIL;
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1934 }
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1935 }
23735
7caffd835aa1 patch 8.2.2409: Vim9: profiling only works for one function
Bram Moolenaar <Bram@vim.org>
parents: 23729
diff changeset
1936 if (func_needs_compiling(ufunc, PROFILING(ufunc))
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1937 && compile_def_function(ufunc, ufunc->uf_ret_type == NULL,
23735
7caffd835aa1 patch 8.2.2409: Vim9: profiling only works for one function
Bram Moolenaar <Bram@vim.org>
parents: 23729
diff changeset
1938 PROFILING(ufunc), NULL) == FAIL)
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1939 return FAIL;
19944
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1940 }
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1941
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1942 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
1943 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
1944 : 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
1945 return FAIL;
22326
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
1946 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
1947 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1948 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
1949 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
1950 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1951 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1952 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1953 // 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
1954 // 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
1955 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
1956 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
1957 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1959 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
1960 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
1961 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1962 // add return value
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1963 ((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
1964 ++stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1965
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1966 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1967 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1968
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1969 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1970 * 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
1971 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1972 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1973 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
1974 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1975 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1976 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
1977
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1978 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
1979 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
1980 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1981 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
1982 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
1983
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1984 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
1985 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
1986 return FAIL;
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
1987 // add return value
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
1988 ((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
1989 ++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
1990
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1991 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1992 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1993
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1994 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1995 * 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
1996 * "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
1997 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1998 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
1999 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
2000 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
2001 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
2002 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
2003 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
2004 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
2005 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2006 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2007 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
2008 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
2009
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
2010 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
2011
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
2012 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
2013 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
2014 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
2015 {
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
2016 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
2017 {
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
2018 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
2019
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
2020 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
2021 {
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
2022 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
2023 return FAIL;
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
2024 }
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
2025 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
2026 {
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
2027 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
2028 return FAIL;
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
2029 }
22816
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2030 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
2031 {
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2032 int i;
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2033
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2034 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
2035 {
24402
009a540f16a6 patch 8.2.2741: Vim9: Partial call does not check right arguments
Bram Moolenaar <Bram@vim.org>
parents: 24400
diff changeset
2036 int offset = -argcount + i - (at_top ? 0 : 1);
22816
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2037 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
2038 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
2039 type_T *expected;
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2040
23527
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23525
diff changeset
2041 if (varargs && i >= type->tt_argcount - 1)
22816
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2042 expected = type->tt_args[
23527
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23525
diff changeset
2043 type->tt_argcount - 1]->tt_member;
24272
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
2044 else if (i >= type->tt_min_argcount
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
2045 && actual == &t_special)
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
2046 expected = &t_any;
22816
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2047 else
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2048 expected = type->tt_args[i];
23691
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
2049 if (need_type(actual, expected, offset, i + 1,
22816
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2050 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
2051 {
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2052 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
2053 return FAIL;
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2054 }
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2055 }
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2056 }
20281
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
2057 }
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
2058 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
2059 }
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
2060 else
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
2061 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2062 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
2063 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
2064 }
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
2065
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2066 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
2067 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2068 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
2069 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
2070
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2071 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
2072
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2073 // 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
2074 ((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
2075
19862
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19860
diff changeset
2076 // 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
2077 // the return value.
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19860
diff changeset
2078 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
2079 return FAIL;
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19860
diff changeset
2080
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2081 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2082 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2083
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2084 /*
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
2085 * 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
2086 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2087 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
2088 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
2089 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2090 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2091 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
2092 type_T *type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2093
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
2094 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
2095 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
2096 return FAIL;
20830
9064044fd4f6 patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
2097 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
2098
19461
08ef11a81daa patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
2099 // 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
2100 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
2101 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
2102 {
08ef11a81daa patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
2103 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
2104 return FAIL;
08ef11a81daa patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
2105 }
08ef11a81daa patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
2106 // 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
2107 if (type->tt_type == VAR_DICT)
23561
647ff61c0bcd patch 8.2.2323: Vim9: error when inferring type from empty dict/list
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2108 {
647ff61c0bcd patch 8.2.2323: Vim9: error when inferring type from empty dict/list
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2109 ((type_T **)stack->ga_data)[stack->ga_len - 1] =
647ff61c0bcd patch 8.2.2323: Vim9: error when inferring type from empty dict/list
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2110 type->tt_member == &t_unknown ? &t_any : type->tt_member;
647ff61c0bcd patch 8.2.2323: Vim9: error when inferring type from empty dict/list
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2111 }
19181
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 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2114 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2115
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 * 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
2118 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2119 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2120 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
2121 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2122 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2123
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
2124 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
2125 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
2126 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2127 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
2128 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
2129
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2130 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2131 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2132
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2133 /*
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
2134 * 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
2135 */
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2136 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
2137 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
2138 {
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2139 isn_T *isn;
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2140
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
2141 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
2142 return FAIL;
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2143 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
2144
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2145 return OK;
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2146 }
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2147
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
2148 /*
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
2149 * 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
2150 */
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
2151 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
2152 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
2153 {
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
2154 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
2155
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
2156 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
2157 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
2158 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
2159 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
2160 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
2161 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
2162 }
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
2163
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2164 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2165 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
2166 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2167 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2168
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
2169 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
2170 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
2171 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2172 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
2173 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2174 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2175
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2176 static int
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2177 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
2178 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2179 isn_T *isn;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2180
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2181 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
2182 return FAIL;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2183 isn->isn_arg.number = count;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2184 return OK;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2185 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2186
23156
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2187 /*
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2188 * 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
2189 */
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2190 static int
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2191 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
2192 {
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2193 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
2194 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
2195
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2196 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
2197 return FAIL;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2198 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
2199
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2200 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
2201 return FAIL;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2202 ((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
2203 ++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
2204 return OK;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2205 }
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2206
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2207 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
2208 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
2209 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2210 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
2211
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2212 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
2213 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
2214 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
2215 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
2216 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
2217 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
2218 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2219
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2220 /*
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
2221 * 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
2222 */
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2223 static int
22699
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 22697
diff changeset
2224 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
2225 {
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2226 isn_T *isn;
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2227
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
2228 if (has_cmdmod(cmod))
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
2229 {
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
2230 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
2231
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
2232 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
2233 return FAIL;
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
2234 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
2235 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
2236 return FAIL;
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
2237 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
2238 // 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
2239 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
2240 }
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
2241
22691
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2242 return OK;
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2243 }
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2244
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2245 static int
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
2246 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
2247 {
23100
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23088
diff changeset
2248 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
2249 return FAIL;
23586
8c5374ec8a3d patch 8.2.2335: Vim9: "silent return" does not restore command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 23578
diff changeset
2250 cctx->ctx_has_cmdmod = FALSE;
22691
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2251 return OK;
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2252 }
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2253
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
2254 static int
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
2255 misplaced_cmdmod(cctx_T *cctx)
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2256 {
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2257 garray_T *instr = &cctx->ctx_instr;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2258
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2259 if (cctx->ctx_has_cmdmod
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2260 && ((isn_T *)instr->ga_data)[instr->ga_len - 1].isn_type
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2261 == ISN_CMDMOD)
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2262 {
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
2263 emsg(_(e_misplaced_command_modifier));
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
2264 return TRUE;
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
2265 }
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
2266 return FALSE;
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2267 }
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2268
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2269 /*
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2270 * Get the index of the current instruction.
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2271 * This compenstates for a preceding ISN_CMDMOD and ISN_PROF_START.
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2272 */
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2273 static int
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2274 current_instr_idx(cctx_T *cctx)
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2275 {
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2276 garray_T *instr = &cctx->ctx_instr;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2277 int idx = instr->ga_len;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2278
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2279 if (cctx->ctx_has_cmdmod && ((isn_T *)instr->ga_data)[idx - 1]
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2280 .isn_type == ISN_CMDMOD)
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2281 --idx;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2282 #ifdef FEAT_PROFILE
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2283 if (cctx->ctx_profiling && ((isn_T *)instr->ga_data)[idx - 1]
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2284 .isn_type == ISN_PROF_START)
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2285 --idx;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2286 #endif
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2287 return idx;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2288 }
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2289
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
2290 #ifdef FEAT_PROFILE
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
2291 static void
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
2292 may_generate_prof_end(cctx_T *cctx, int prof_lnum)
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
2293 {
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
2294 if (cctx->ctx_profiling && prof_lnum >= 0)
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
2295 generate_instr(cctx, ISN_PROF_END);
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
2296 }
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
2297 #endif
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
2298
22691
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2299 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2300 * 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
2301 * 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
2302 */
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2303 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
2304 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
2305 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
2306 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
2307 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
2308 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
2309 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
2310 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2311 lvar_T *lvar;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2312
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2313 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
2314 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2315 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
2316 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2317 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2318
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2319 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
2320 return NULL;
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2321 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
2322 CLEAR_POINTER(lvar);
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2323
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2324 // 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
2325 // 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
2326 // 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
2327 // 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
2328 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
2329
20830
9064044fd4f6 patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
2330 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
2331 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
2332 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
2333
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2334 return lvar;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2335 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2336
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2337 /*
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2338 * 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
2339 */
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2340 static void
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2341 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
2342 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2343 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
2344 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2345 int idx;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2346 lvar_T *lvar;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2347
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2348 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
2349 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2350 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
2351 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
2352 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2353 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2354 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
2355 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2356
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2357 /*
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2358 * 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
2359 */
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2360 static void
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2361 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
2362 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2363 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
2364 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
2365 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2366
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2367 /*
23578
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2368 * If "check_writable" is ASSIGN_CONST give an error if the variable was
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2369 * defined with :final or :const, if "check_writable" is ASSIGN_FINAL give an
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2370 * error if the variable was defined with :const.
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2371 */
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2372 static int
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2373 check_item_writable(svar_T *sv, int check_writable, char_u *name)
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2374 {
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2375 if ((check_writable == ASSIGN_CONST && sv->sv_const != 0)
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2376 || (check_writable == ASSIGN_FINAL
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2377 && sv->sv_const == ASSIGN_CONST))
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2378 {
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2379 semsg(_(e_readonlyvar), name);
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2380 return FAIL;
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2381 }
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2382 return OK;
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2383 }
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2384
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2385 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2386 * Find "name" in script-local items of script "sid".
23578
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2387 * Pass "check_writable" to check_item_writable().
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2388 * 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
2389 * If found but not in "sn_var_vals" returns -1.
23578
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2390 * If not found or the variable is not writable returns -2.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2391 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2392 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
2393 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
2394 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2395 hashtab_T *ht;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2396 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
2397 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
2398 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
2399 int idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2400
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2401 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
2402 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
2403 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
2404 {
22598
c7ef64b85e9b patch 8.2.1847: Vim9: using negative value for unsigned type
Bram Moolenaar <Bram@vim.org>
parents: 22596
diff changeset
2405 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
2406
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2407 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
2408 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
2409 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
2410 sv = ((svar_T *)si->sn_var_vals.ga_data) + idx;
23578
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2411 if (check_item_writable(sv, check_writable, name) == FAIL)
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2412 return -2;
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2413 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
2414 }
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2415
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2416 // 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
2417 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
2418 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
2419 if (di == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2420 return -2;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2421
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2422 // 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
2423 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
2424 {
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2425 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
2426 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
2427 {
23578
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2428 if (check_item_writable(sv, check_writable, name) == FAIL)
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2429 return -2;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2430 return idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2431 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2432 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2433 return -1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2434 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2435
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2436 /*
20840
0600ab7b9f09 patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2437 * 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
2438 * NULL.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2439 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2440 imported_T *
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
2441 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
2442 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2443 int idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2444
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2445 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
2446 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2447 if (cctx != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2448 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
2449 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2450 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
2451 + idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2452
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
2453 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
2454 : 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
2455 && 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
2456 return import;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2457 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2458
21699
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2459 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
2460 }
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2461
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2462 imported_T *
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2463 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
2464 {
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2465 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
2466 int idx;
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2467
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2468 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
2469 return NULL;
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2470 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
2471 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
2472 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2473 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
2474
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
2475 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
2476 : 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
2477 && 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
2478 return import;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2479 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2480 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2481 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2482
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2483 /*
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2484 * 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
2485 */
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2486 static void
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2487 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
2488 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2489 int idx;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2490
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2491 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
2492 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2493 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
2494
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2495 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
2496 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2497 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
2498 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2499
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2500 /*
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2501 * 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
2502 * 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
2503 * 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
2504 */
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
2505 char_u *
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
2506 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
2507 {
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2508 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
2509
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2510 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
2511 {
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2512 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
2513 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
2514
21767
9529a2367d3e patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents: 21763
diff changeset
2515 // 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
2516 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
2517 {
9529a2367d3e patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents: 21763
diff changeset
2518 p = skipwhite(line);
24158
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
2519 if (vim9_bad_comment(p))
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
2520 return NULL;
21767
9529a2367d3e patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents: 21763
diff changeset
2521 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
2522 return p;
9529a2367d3e patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents: 21763
diff changeset
2523 }
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2524 }
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2525 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
2526 }
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2527
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2528 /*
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2529 * 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
2530 * 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
2531 * 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
2532 * 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
2533 */
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2534 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
2535 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
2536 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2537 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
2538
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2539 *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
2540 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
2541 {
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
2542 *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
2543 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
2544 return *nextp;
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2545 }
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2546 return p;
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2547 }
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2548
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2549 /*
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2550 * 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
2551 * 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
2552 * 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
2553 */
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
2554 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
2555 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
2556 {
20059
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20055
diff changeset
2557 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
2558
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2559 do
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2560 {
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2561 ++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
2562 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
2563 {
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20055
diff changeset
2564 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
2565 break;
20059
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20055
diff changeset
2566 }
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2567 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
2568 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
2569 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
2570 } 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
2571 || (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
2572 return line;
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2573 }
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2574
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2575 /*
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
2576 * 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
2577 * 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
2578 * 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
2579 * 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
2580 */
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2581 static int
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
2582 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
2583 {
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
2584 *arg = skipwhite(whitep);
24158
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
2585 if (vim9_bad_comment(*arg))
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
2586 return FAIL;
21353
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
2587 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
2588 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2589 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
2590
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2591 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
2592 return FAIL;
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2593 *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
2594 }
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2595 return OK;
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2596 }
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2597
21248
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2598 /*
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2599 * 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
2600 */
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2601 static int
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2602 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
2603 {
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2604 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
2605 {
23122
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23114
diff changeset
2606 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
2607 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
2608 return FAIL;
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2609 }
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2610 return OK;
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2611 }
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2612
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2613
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2614 // 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
2615 // 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
2616 // 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
2617 // 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
2618 // 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
2619 // 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
2620 #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
2621 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
2622 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
2623 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
2624 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
2625 // 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
2626 } 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
2627
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
2628 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
2629 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
2630 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
2631
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2632 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2633 * 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
2634 * "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
2635 * 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
2636 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2637 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
2638 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
2639 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2640 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
2641 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2642 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
2643 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2644 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
2645 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2646 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
2647 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
2648 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2649 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
2650 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
2651 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2652 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
2653 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
2654 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2655 #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
2656 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
2657 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
2658 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2659 #endif
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2660 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
2661 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
2662 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
2663 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2664 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
2665 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
2666 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
2667 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2668 default:
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2669 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
2670 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
2671 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
2672 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2673 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
2674 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2675 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
2676 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2677
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2678 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2679 * 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
2680 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2681 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
2682 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
2683 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2684 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
2685 int ret = OK;
20332
a407e243c55c patch 8.2.0721: Vim9: leaking memory when skipping
Bram Moolenaar <Bram@vim.org>
parents: 20328
diff changeset
2686 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
2687
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
2688 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
2689 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
2690 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
2691 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
2692 ppconst->pp_used = 0;
20332
a407e243c55c patch 8.2.0721: Vim9: leaking memory when skipping
Bram Moolenaar <Bram@vim.org>
parents: 20328
diff changeset
2693 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
2694 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
2695 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2696
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2697 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2698 * 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
2699 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2700 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
2701 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
2702 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2703 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
2704
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2705 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
2706 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
2707 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
2708 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2709
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2710 /*
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2711 * Compile getting a member from a list/dict/string/blob. Stack has the
24602
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2712 * indexable value and the index or the two indexes of a slice.
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2713 */
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2714 static int
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2715 compile_member(int is_slice, cctx_T *cctx)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2716 {
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2717 type_T **typep;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2718 garray_T *stack = &cctx->ctx_type_stack;
24602
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2719 vartype_T vartype;
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2720 type_T *idxtype;
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2721
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2722 // We can index a list, dict and blob. If we don't know the type
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2723 // we can use the index value type. If we still don't know use an "ANY"
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2724 // instruction.
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2725 typep = ((type_T **)stack->ga_data) + stack->ga_len
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2726 - (is_slice ? 3 : 2);
24602
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2727 vartype = (*typep)->tt_type;
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2728 idxtype = ((type_T **)stack->ga_data)[stack->ga_len - 1];
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2729 // If the index is a string, the variable must be a Dict.
24602
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2730 if (*typep == &t_any && idxtype == &t_string)
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2731 vartype = VAR_DICT;
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2732 if (vartype == VAR_STRING || vartype == VAR_LIST || vartype == VAR_BLOB)
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2733 {
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2734 if (need_type(idxtype, &t_number, -1, 0, cctx, FALSE, FALSE) == FAIL)
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2735 return FAIL;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2736 if (is_slice)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2737 {
24602
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2738 idxtype = ((type_T **)stack->ga_data)[stack->ga_len - 2];
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2739 if (need_type(idxtype, &t_number, -2, 0, cctx,
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2740 FALSE, FALSE) == FAIL)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2741 return FAIL;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2742 }
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2743 }
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2744
24602
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2745 if (vartype == VAR_DICT)
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2746 {
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2747 if (is_slice)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2748 {
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2749 emsg(_(e_cannot_slice_dictionary));
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2750 return FAIL;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2751 }
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2752 if ((*typep)->tt_type == VAR_DICT)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2753 {
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2754 *typep = (*typep)->tt_member;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2755 if (*typep == &t_unknown)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2756 // empty dict was used
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2757 *typep = &t_any;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2758 }
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2759 else
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2760 {
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2761 if (need_type(*typep, &t_dict_any, -2, 0, cctx,
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2762 FALSE, FALSE) == FAIL)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2763 return FAIL;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2764 *typep = &t_any;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2765 }
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2766 if (may_generate_2STRING(-1, cctx) == FAIL)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2767 return FAIL;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2768 if (generate_instr_drop(cctx, ISN_MEMBER, 1) == FAIL)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2769 return FAIL;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2770 }
24602
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2771 else if (vartype == VAR_STRING)
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2772 {
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2773 *typep = &t_string;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2774 if ((is_slice
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2775 ? generate_instr_drop(cctx, ISN_STRSLICE, 2)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2776 : generate_instr_drop(cctx, ISN_STRINDEX, 1)) == FAIL)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2777 return FAIL;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2778 }
24602
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2779 else if (vartype == VAR_BLOB)
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2780 {
24432
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2781 if (is_slice)
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2782 {
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2783 *typep = &t_blob;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2784 if (generate_instr_drop(cctx, ISN_BLOBSLICE, 2) == FAIL)
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2785 return FAIL;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2786 }
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2787 else
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2788 {
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2789 *typep = &t_number;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2790 if (generate_instr_drop(cctx, ISN_BLOBINDEX, 1) == FAIL)
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2791 return FAIL;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2792 }
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2793 }
24602
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2794 else if (vartype == VAR_LIST || *typep == &t_any)
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2795 {
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2796 if (is_slice)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2797 {
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2798 if (generate_instr_drop(cctx,
24602
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2799 vartype == VAR_LIST ? ISN_LISTSLICE : ISN_ANYSLICE,
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2800 2) == FAIL)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2801 return FAIL;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2802 }
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2803 else
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2804 {
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2805 if ((*typep)->tt_type == VAR_LIST)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2806 {
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2807 *typep = (*typep)->tt_member;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2808 if (*typep == &t_unknown)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2809 // empty list was used
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2810 *typep = &t_any;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2811 }
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2812 if (generate_instr_drop(cctx,
24602
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2813 vartype == VAR_LIST ? ISN_LISTINDEX : ISN_ANYINDEX, 1)
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2814 == FAIL)
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2815 return FAIL;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2816 }
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2817 }
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2818 else
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2819 {
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2820 emsg(_(e_string_list_dict_or_blob_required));
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2821 return FAIL;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2822 }
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2823 return OK;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2824 }
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2825
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2826 /*
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2827 * 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
2828 * leading "s:".
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2829 * 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
2830 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2831 static int
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2832 compile_load_scriptvar(
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2833 cctx_T *cctx,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2834 char_u *name, // variable NUL terminated
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2835 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
2836 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
2837 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
2838 {
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2839 scriptitem_T *si;
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2840 int idx;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2841 imported_T *import;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2842
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2843 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
2844 return FAIL;
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2845 si = SCRIPT_ITEM(current_sctx.sc_sid);
23578
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2846 idx = get_script_item_idx(current_sctx.sc_sid, name, 0, cctx);
19451
b26e96f7c12f patch 8.2.0283: Vim9: failing to load script var not tested
Bram Moolenaar <Bram@vim.org>
parents: 19437
diff changeset
2847 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
2848 {
19451
b26e96f7c12f patch 8.2.0283: Vim9: failing to load script var not tested
Bram Moolenaar <Bram@vim.org>
parents: 19437
diff changeset
2849 // 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
2850 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
2851 &t_any);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2852 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2853 if (idx >= 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2854 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2855 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
2856
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
2857 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
2858 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
2859 return OK;
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
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
2862 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
2863 if (import != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2864 {
23364
17a0e32eefd4 patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents: 23362
diff changeset
2865 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
2866 {
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2867 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
2868 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
2869 int cc;
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2870 ufunc_T *ufunc;
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2871 type_T *type;
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2872
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2873 // 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
2874 if (*p != '.')
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2875 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2876 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
2877 return FAIL;
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2878 }
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2879 ++p;
19818
c1c88b333481 patch 8.2.0465: Vim9: dead code and wrong return type
Bram Moolenaar <Bram@vim.org>
parents: 19785
diff changeset
2880 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
2881 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2882 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
2883 return FAIL;
c1c88b333481 patch 8.2.0465: Vim9: dead code and wrong return type
Bram Moolenaar <Bram@vim.org>
parents: 19785
diff changeset
2884 }
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2885
21146
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2886 // 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
2887 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
2888 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
2889 ++p;
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2890 cc = *p;
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2891 *p = NUL;
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2892
24116
a028cb6898a2 patch 8.2.2599: build failure
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
2893 idx = find_exported(import->imp_sid, exp_name, &ufunc, &type,
a028cb6898a2 patch 8.2.2599: build failure
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
2894 cctx, TRUE);
21146
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2895 *p = cc;
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2896 p = skipwhite(p);
24283
bcfff560e089 patch 8.2.2682: Vim9: cannot find Name.Func from "import * as Name"
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
2897 *end = p;
bcfff560e089 patch 8.2.2682: Vim9: cannot find Name.Func from "import * as Name"
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
2898
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2899 if (idx < 0)
24283
bcfff560e089 patch 8.2.2682: Vim9: cannot find Name.Func from "import * as Name"
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
2900 {
bcfff560e089 patch 8.2.2682: Vim9: cannot find Name.Func from "import * as Name"
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
2901 if (*p == '(' && ufunc != NULL)
bcfff560e089 patch 8.2.2682: Vim9: cannot find Name.Func from "import * as Name"
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
2902 {
bcfff560e089 patch 8.2.2682: Vim9: cannot find Name.Func from "import * as Name"
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
2903 generate_PUSHFUNC(cctx, ufunc->uf_name, import->imp_type);
bcfff560e089 patch 8.2.2682: Vim9: cannot find Name.Func from "import * as Name"
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
2904 return OK;
bcfff560e089 patch 8.2.2682: Vim9: cannot find Name.Func from "import * as Name"
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
2905 }
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2906 return FAIL;
24283
bcfff560e089 patch 8.2.2682: Vim9: cannot find Name.Func from "import * as Name"
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
2907 }
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2908
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2909 generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2910 import->imp_sid,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2911 idx,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2912 type);
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2913 }
21473
8bcd1ee2630b patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
2914 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
2915 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
2916 else
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2917 generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2918 import->imp_sid,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2919 import->imp_var_vals_idx,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2920 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
2921 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2922 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2923
19530
48e71f948360 patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
2924 if (error)
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2925 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
2926 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2927 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2928
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2929 static int
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2930 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
2931 {
20189
63cc54100ae4 patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents: 20174
diff changeset
2932 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
2933
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2934 if (ufunc == NULL)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2935 return FAIL;
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2936
21469
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
2937 // Need to compile any default values to get the argument types.
23735
7caffd835aa1 patch 8.2.2409: Vim9: profiling only works for one function
Bram Moolenaar <Bram@vim.org>
parents: 23729
diff changeset
2938 if (func_needs_compiling(ufunc, PROFILING(ufunc))
7caffd835aa1 patch 8.2.2409: Vim9: profiling only works for one function
Bram Moolenaar <Bram@vim.org>
parents: 23729
diff changeset
2939 && compile_def_function(ufunc, TRUE, PROFILING(ufunc), NULL)
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
2940 == FAIL)
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
2941 return FAIL;
21473
8bcd1ee2630b patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
2942 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
2943 }
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2944
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2945 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2946 * 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
2947 * "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
2948 * "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
2949 * 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
2950 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2951 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
2952 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
2953 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
2954 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
2955 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
2956 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
2957 int error)
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 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
2960 char_u *name = NULL;
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2961 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
2962 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
2963 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
2964
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2965 if (*(*arg + 1) == ':')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2966 {
19822
fc3cdc819d80 patch 8.2.0467: Vim9: some errors are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19818
diff changeset
2967 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
2968 {
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
2969 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
2970
24390
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
2971 // load dictionary of namespace
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
2972 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
2973 {
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2974 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
2975 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
2976 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
2977 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
2978 default:
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2979 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
2980 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
2981 }
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2982 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
2983 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
2984 res = OK;
19822
fc3cdc819d80 patch 8.2.0467: Vim9: some errors are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19818
diff changeset
2985 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2986 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2987 {
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
2988 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
2989
24390
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
2990 // load namespaced variable
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
2991 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
2992 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
2993 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
2994
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2995 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
2996 {
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2997 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
2998 break;
24390
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
2999 case 's': if (is_expr && ASCII_ISUPPER(*name)
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3000 && find_func(name, FALSE, cctx) != NULL)
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3001 res = generate_funcref(cctx, name);
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3002 else
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3003 res = compile_load_scriptvar(cctx, name,
24295
7f634eae21fe patch 8.2.2688: Vim9: crash when using s: for script variable
Bram Moolenaar <Bram@vim.org>
parents: 24293
diff changeset
3004 NULL, &end, error);
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
3005 break;
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3006 case 'g': if (vim_strchr(name, AUTOLOAD_CHAR) == NULL)
24390
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3007 {
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3008 if (is_expr && ASCII_ISUPPER(*name)
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3009 && find_func(name, FALSE, cctx) != NULL)
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3010 res = generate_funcref(cctx, name);
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3011 else
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3012 isn_type = ISN_LOADG;
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3013 }
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3014 else
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3015 {
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3016 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
3017 vim_free(name);
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3018 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
3019 if (name == NULL)
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3020 return FAIL;
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3021 }
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3022 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
3023 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
3024 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
3025 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
3026 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
3027 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
3028 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
3029 }
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
3030 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
3031 {
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
3032 // 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
3033 // variables can be defined later, thus we don't check if it
24390
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3034 // exists, give an error at runtime.
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
3035 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
3036 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3037 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3038 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3039 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3040 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3041 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
3042 int idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3043 int gen_load = FALSE;
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
3044 int gen_load_outer = 0;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3045
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3046 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
3047 if (name == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3048 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3049
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
3050 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
3051 {
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
3052 if (gen_load_outer == 0)
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
3053 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
3054 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3055 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3056 {
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
3057 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
3058
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
3059 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
3060 {
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
3061 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
3062 idx = lvar.lv_idx;
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
3063 if (lvar.lv_from_outer != 0)
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
3064 gen_load_outer = lvar.lv_from_outer;
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
3065 else
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
3066 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
3067 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3068 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3069 {
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3070 // "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
3071 // already exists in a Vim9 script or when it's imported.
24388
72f3e40f046c patch 8.2.2734: Vim9: cannot use legacy script-local var from :def function
Bram Moolenaar <Bram@vim.org>
parents: 24379
diff changeset
3072 if (script_var_exists(*arg, len, 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
3073 || 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
3074 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
3075
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
3076 // When evaluating an expression and the name starts with an
24390
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3077 // uppercase letter it can be a user defined function.
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3078 // generate_funcref() will fail if the function can't be found.
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3079 if (res == FAIL && is_expr && ASCII_ISUPPER(*name))
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3080 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
3081 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3082 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3083 if (gen_load)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3084 res = generate_LOAD(cctx, ISN_LOAD, idx, NULL, type);
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
3085 if (gen_load_outer > 0)
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
3086 {
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
3087 res = generate_LOADOUTER(cctx, idx, gen_load_outer, type);
21769
f37c1330b15c patch 8.2.1434: Vim9: crash when lambda uses outer function argument
Bram Moolenaar <Bram@vim.org>
parents: 21767
diff changeset
3088 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
3089 }
19181
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
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3092 *arg = end;
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 theend:
19818
c1c88b333481 patch 8.2.0465: Vim9: dead code and wrong return type
Bram Moolenaar <Bram@vim.org>
parents: 19785
diff changeset
3095 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
3096 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
3097 vim_free(name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3098 return res;
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
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3101 static void
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3102 clear_instr_ga(garray_T *gap)
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3103 {
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3104 int idx;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3105
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3106 for (idx = 0; idx < gap->ga_len; ++idx)
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3107 delete_instr(((isn_T *)gap->ga_data) + idx);
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3108 ga_clear(gap);
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3109 }
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3110
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3111 /*
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3112 * Compile a string in a ISN_PUSHS instruction into an ISN_INSTR.
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3113 * Returns FAIL if compilation fails.
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3114 */
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3115 static int
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3116 compile_string(isn_T *isn, cctx_T *cctx)
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3117 {
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3118 char_u *s = isn->isn_arg.string;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3119 garray_T save_ga = cctx->ctx_instr;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3120 int expr_res;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3121 int trailing_error;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3122 int instr_count;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3123 isn_T *instr = NULL;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3124
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3125 // Temporarily reset the list of instructions so that the jump labels are
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3126 // correct.
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3127 cctx->ctx_instr.ga_len = 0;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3128 cctx->ctx_instr.ga_maxlen = 0;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3129 cctx->ctx_instr.ga_data = NULL;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3130 expr_res = compile_expr0(&s, cctx);
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3131 s = skipwhite(s);
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3132 trailing_error = *s != NUL;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3133
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3134 if (expr_res == FAIL || trailing_error)
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3135 {
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3136 if (trailing_error)
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3137 semsg(_(e_trailing_arg), s);
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3138 clear_instr_ga(&cctx->ctx_instr);
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3139 cctx->ctx_instr = save_ga;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3140 return FAIL;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3141 }
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3142
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3143 // Move the generated instructions into the ISN_INSTR instruction, then
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3144 // restore the list of instructions.
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3145 instr_count = cctx->ctx_instr.ga_len;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3146 instr = cctx->ctx_instr.ga_data;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3147 instr[instr_count].isn_type = ISN_FINISH;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3148
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3149 cctx->ctx_instr = save_ga;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3150 vim_free(isn->isn_arg.string);
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3151 isn->isn_type = ISN_INSTR;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3152 isn->isn_arg.instr = instr;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3153 return OK;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3154 }
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3155
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3156 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3157 * 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
3158 * "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
3159 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3160 static int
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3161 compile_arguments(char_u **arg, cctx_T *cctx, int *argcount, int is_searchpair)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3162 {
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3163 char_u *p = *arg;
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3164 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
3165 int must_end = FALSE;
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3166 int instr_count;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3167
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
3168 for (;;)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3169 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3170 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
3171 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
3172 if (*p == ')')
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
3173 {
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
3174 *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
3175 return OK;
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
3176 }
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
3177 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
3178 {
fc3350a38389 patch 8.2.1719: Vim9: no error if comma is missing in between arguments
Bram Moolenaar <Bram@vim.org>
parents: 22326
diff changeset
3179 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
3180 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
3181 }
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
3182
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3183 instr_count = cctx->ctx_instr.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
3184 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
3185 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3186 ++*argcount;
19437
5d34ae66118e patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents: 19423
diff changeset
3187
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3188 if (is_searchpair && *argcount == 5
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3189 && cctx->ctx_instr.ga_len == instr_count + 1)
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3190 {
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3191 isn_T *isn = ((isn_T *)cctx->ctx_instr.ga_data) + instr_count;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3192
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3193 // {skip} argument of searchpair() can be compiled if not empty
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3194 if (isn->isn_type == ISN_PUSHS && *isn->isn_arg.string != NUL)
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3195 compile_string(isn, cctx);
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3196 }
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3197
19437
5d34ae66118e patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents: 19423
diff changeset
3198 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
3199 {
23888
d95403445b6b patch 8.2.2486: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23882
diff changeset
3200 semsg(_(e_no_white_space_allowed_before_str_str), ",", p);
19437
5d34ae66118e patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents: 19423
diff changeset
3201 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
3202 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3203 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
3204 {
5d34ae66118e patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents: 19423
diff changeset
3205 ++p;
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
3206 if (*p != NUL && !VIM_ISWHITE(*p))
23877
85cf06ddb2a8 patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23837
diff changeset
3207 semsg(_(e_white_space_required_after_str_str), ",", p - 1);
19437
5d34ae66118e patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents: 19423
diff changeset
3208 }
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
3209 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
3210 must_end = TRUE;
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3211 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
3212 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
3213 }
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3214 failret:
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
3215 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
3216 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3217 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3218
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3219 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3220 * 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
3221 * "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
3222 * "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
3223 * Instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3224 * EVAL arg1
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3225 * EVAL arg2
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3226 * BCALL / DCALL / UCALL
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3227 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3228 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
3229 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
3230 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
3231 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
3232 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
3233 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
3234 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
3235 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3236 char_u *name = *arg;
19257
5aab9c306181 patch 8.2.0187: reduntant code
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
3237 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
3238 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
3239 char_u namebuf[100];
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3240 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
3241 char_u *tofree = NULL;
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3242 int error = FCERR_NONE;
22914
54f796fb7cb2 patch 8.2.2004: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents: 22910
diff changeset
3243 ufunc_T *ufunc = NULL;
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3244 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
3245 int is_autoload;
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3246 int is_searchpair;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3247
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3248 // 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
3249 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
3250 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3251 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
3252 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
3253
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3254 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
3255 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
3256 (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
3257 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
3258 (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
3259 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
3260 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
3261 && !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
3262 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3263 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
3264
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3265 *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
3266 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
3267 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
3268 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
3269 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
3270 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
3271 ++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
3272 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
3273 }
20332
a407e243c55c patch 8.2.0721: Vim9: leaking memory when skipping
Bram Moolenaar <Bram@vim.org>
parents: 20328
diff changeset
3274 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
3275 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3276
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3277 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
3278 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
3279
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3280 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
3281 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
3282 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
3283 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3284 }
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3285 vim_strncpy(namebuf, *arg, varlen);
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3286 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
3287
24608
cb031f421ece patch 8.2.2843: Vim9: skip argument to searchpairpos() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
3288 // We handle the "skip" argument of searchpair() and searchpairpos()
cb031f421ece patch 8.2.2843: Vim9: skip argument to searchpairpos() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
3289 // differently.
cb031f421ece patch 8.2.2843: Vim9: skip argument to searchpairpos() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
3290 is_searchpair = (varlen == 6 && STRNCMP(*arg, "search", 6) == 0)
cb031f421ece patch 8.2.2843: Vim9: skip argument to searchpairpos() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
3291 || (varlen == 9 && STRNCMP(*arg, "searchpos", 9) == 0)
cb031f421ece patch 8.2.2843: Vim9: skip argument to searchpairpos() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
3292 || (varlen == 10 && STRNCMP(*arg, "searchpair", 10) == 0)
cb031f421ece patch 8.2.2843: Vim9: skip argument to searchpairpos() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
3293 || (varlen == 13 && STRNCMP(*arg, "searchpairpos", 13) == 0);
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3294
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3295 *arg = skipwhite(*arg + varlen + 1);
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3296 if (compile_arguments(arg, cctx, &argcount, is_searchpair) == FAIL)
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3297 goto theend;
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3298
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3299 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
3300 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
3301 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3302 int idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3303
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3304 // builtin function
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3305 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
3306 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
3307 {
23816
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23806
diff changeset
3308 if (STRCMP(name, "flatten") == 0)
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23806
diff changeset
3309 {
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23806
diff changeset
3310 emsg(_(e_cannot_use_flatten_in_vim9_script));
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23806
diff changeset
3311 goto theend;
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23806
diff changeset
3312 }
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23806
diff changeset
3313
22633
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
3314 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
3315 {
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
3316 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
3317 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
3318 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
3319
22772
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
3320 // 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
3321 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
3322 {
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
3323 // 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
3324 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
3325 idx = -1;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
3326 }
22637
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3327 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
3328 {
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3329 // 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
3330 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
3331 idx = -1;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3332 }
22633
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
3333 }
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
3334
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
3335 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
3336 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
3337 }
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
3338 else
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
3339 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
3340 goto theend;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3341 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3342
22910
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
3343 // 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
3344 // 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
3345 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
3346 && 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
3347 {
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
3348 // 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
3349 // 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
3350 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
3351 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
3352 {
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
3353 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
3354 goto theend;
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
3355 }
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3356 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3357
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3358 // 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
3359 // 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
3360 // 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
3361 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
3362 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
3363 && 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
3364 {
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
3365 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
3366 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
3367
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
3368 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
3369 goto theend;
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3370 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3371
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
3372 // 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
3373 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
3374 {
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
3375 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
3376 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
3377 }
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
3378
20140
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20138
diff changeset
3379 // 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
3380 // 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
3381 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
3382 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
3383 else
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20138
diff changeset
3384 semsg(_(e_unknownfunc), namebuf);
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3385
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3386 theend:
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3387 vim_free(tofree);
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3388 return res;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3389 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3390
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3391 // 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
3392 #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
3393
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3394 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3395 * 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
3396 * 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
3397 * 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
3398 * 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
3399 * valid name.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3400 */
22936
00b0275ffe7f patch 8.2.2015: Vim9: literal dict #{} is not like any other language
Bram Moolenaar <Bram@vim.org>
parents: 22932
diff changeset
3401 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
3402 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
3403 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3404 char_u *p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3405
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3406 // 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
3407 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
3408 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3409
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3410 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
3411 // 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
3412 // 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
3413 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
3414 || !use_namespace
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3415 || 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
3416 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3417 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3418 }
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3421 * 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
3422 * 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
3423 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3424 char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3425 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
3426 {
19583
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
3427 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
3428 typval_T rettv;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3429
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3430 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
3431 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3432
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3433 // 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
3434 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
3435 p = arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3436 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3437 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3438 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3439
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3440 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3441 * 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
3442 * "*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
3443 * 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
3444 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3445 static int
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3446 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
3447 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3448 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
3449 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
3450 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
3451 int is_const;
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3452 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
3453
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3454 for (;;)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3455 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3456 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
3457 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3458 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
3459 return FAIL;
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3460 }
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
3461 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
3462 {
23888
d95403445b6b patch 8.2.2486: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23882
diff changeset
3463 semsg(_(e_no_white_space_allowed_before_str_str), ",", p);
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
3464 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
3465 }
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3466 if (*p == ']')
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3467 {
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3468 ++p;
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3469 break;
19830
6500dcaf8e1a patch 8.2.0471: missing change to compile_list()
Bram Moolenaar <Bram@vim.org>
parents: 19822
diff changeset
3470 }
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3471 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
3472 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3473 if (!is_const)
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3474 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
3475 ++count;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3476 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
3477 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3478 ++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
3479 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
3480 {
23877
85cf06ddb2a8 patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23837
diff changeset
3481 semsg(_(e_white_space_required_after_str_str), ",", p - 1);
21216
bcd08812cde3 patch 8.2.1159: Vim9: no error for missing space after a comma
Bram Moolenaar <Bram@vim.org>
parents: 21210
diff changeset
3482 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
3483 }
bcd08812cde3 patch 8.2.1159: Vim9: no error for missing space after a comma
Bram Moolenaar <Bram@vim.org>
parents: 21210
diff changeset
3484 }
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3485 whitep = p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3486 p = skipwhite(p);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3487 }
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3488 *arg = p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3489
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3490 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
3491 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
3492 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3493
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3494 /*
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
3495 * Parse a lambda: "(arg, arg) => expr"
24188
c20e763bc73c patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents: 24158
diff changeset
3496 * "*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
3497 * 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
3498 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3499 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3500 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
3501 {
23368
a7cbdb9294c4 patch 8.2.2227: Vim9: recognizing lambda is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 23364
diff changeset
3502 int r;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3503 typval_T rettv;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3504 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
3505 evalarg_T evalarg;
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
3506
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
3507 CLEAR_FIELD(evalarg);
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
3508 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
3509 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
3510
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3511 // 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
3512 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
3513 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
3514 {
1064b9f05b0a patch 8.2.1862: vim9: memory leak when compiling lambda fails
Bram Moolenaar <Bram@vim.org>
parents: 22614
diff changeset
3515 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
3516 return r;
22627
1064b9f05b0a patch 8.2.1862: vim9: memory leak when compiling lambda fails
Bram Moolenaar <Bram@vim.org>
parents: 22614
diff changeset
3517 }
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
3518
23318
c76240efdf02 patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents: 23310
diff changeset
3519 // "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
3520 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
3521 ++ufunc->uf_refcount;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
3522 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
3523
23318
c76240efdf02 patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents: 23310
diff changeset
3524 // Compile the function into instructions.
23735
7caffd835aa1 patch 8.2.2409: Vim9: profiling only works for one function
Bram Moolenaar <Bram@vim.org>
parents: 23729
diff changeset
3525 compile_def_function(ufunc, TRUE, PROFILING(ufunc), cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3526
24190
5f3a2d31c48d patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents: 24188
diff changeset
3527 // evalarg.eval_tofree_cmdline may have a copy of the last line and "*arg"
5f3a2d31c48d patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents: 24188
diff changeset
3528 // points into it. Point to the original line to avoid a dangling pointer.
5f3a2d31c48d patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents: 24188
diff changeset
3529 if (evalarg.eval_tofree_cmdline != NULL)
5f3a2d31c48d patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents: 24188
diff changeset
3530 {
5f3a2d31c48d patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents: 24188
diff changeset
3531 size_t off = *arg - evalarg.eval_tofree_cmdline;
5f3a2d31c48d patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents: 24188
diff changeset
3532
5f3a2d31c48d patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents: 24188
diff changeset
3533 *arg = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum]
5f3a2d31c48d patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents: 24188
diff changeset
3534 + off;
5f3a2d31c48d patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents: 24188
diff changeset
3535 }
5f3a2d31c48d patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents: 24188
diff changeset
3536
21220
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21218
diff changeset
3537 clear_evalarg(&evalarg, NULL);
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21218
diff changeset
3538
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
3539 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
3540 {
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
3541 // 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
3542 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
3543
22324
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
3544 // 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
3545 // 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
3546 // 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
3547 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
3548 }
21353
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
3549
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
3550 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
3551 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3552 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3553
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3554 /*
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
3555 * 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
3556 * "*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
3557 * 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
3558 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3559 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
3560 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
3561 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3562 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
3563 int count = 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3564 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
3565 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
3566 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
3567 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
3568 int is_const;
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3569 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
3570
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3571 if (d == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3572 return FAIL;
23515
8cce160b9183 patch 8.2.2300: Vim9: wrong order on type stack when using dict
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
3573 if (generate_ppconst(cctx, ppconst) == FAIL)
8cce160b9183 patch 8.2.2300: Vim9: wrong order on type stack when using dict
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
3574 return FAIL;
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3575 for (;;)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3576 {
22936
00b0275ffe7f patch 8.2.2015: Vim9: literal dict #{} is not like any other language
Bram Moolenaar <Bram@vim.org>
parents: 22932
diff changeset
3577 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
3578
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3579 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
3580 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3581 *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
3582 goto failret;
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3583 }
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3584
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3585 if (**arg == '}')
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3586 break;
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3587
23088
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3588 if (**arg == '[')
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3589 {
22936
00b0275ffe7f patch 8.2.2015: Vim9: literal dict #{} is not like any other language
Bram Moolenaar <Bram@vim.org>
parents: 22932
diff changeset
3590 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
3591
23088
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3592 // {[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
3593 *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
3594 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
3595 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3596 isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1;
23827
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23816
diff changeset
3597 if (isn->isn_type == ISN_PUSHNR)
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23816
diff changeset
3598 {
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23816
diff changeset
3599 char buf[NUMBUFLEN];
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23816
diff changeset
3600
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23816
diff changeset
3601 // Convert to string at compile time.
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23816
diff changeset
3602 vim_snprintf(buf, NUMBUFLEN, "%lld", isn->isn_arg.number);
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23816
diff changeset
3603 isn->isn_type = ISN_PUSHS;
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23816
diff changeset
3604 isn->isn_arg.string = vim_strsave((char_u *)buf);
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23816
diff changeset
3605 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3606 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
3607 key = isn->isn_arg.string;
23827
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23816
diff changeset
3608 else if (may_generate_2STRING(-1, cctx) == FAIL)
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23816
diff changeset
3609 return FAIL;
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
3610 *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
3611 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
3612 {
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
3613 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
3614 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
3615 }
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
3616 ++*arg;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3617 }
23088
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3618 else
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3619 {
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3620 // {"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
3621 // {'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
3622 // {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
3623 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
3624 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
3625 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
3626 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
3627 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
3628 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3629
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3630 // 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
3631 if (key != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3632 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3633 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
3634 if (item != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3635 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3636 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
3637 goto failret;
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 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
3640 if (item != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3641 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3642 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
3643 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
3644 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
3645 dictitem_free(item);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3646 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3647 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3648
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3649 if (**arg != ':')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3650 {
21759
25b659fa5ca5 patch 8.2.1429: Vim9: no error for missing white after : in dict
Bram Moolenaar <Bram@vim.org>
parents: 21755
diff changeset
3651 if (*skipwhite(*arg) == ':')
23888
d95403445b6b patch 8.2.2486: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23882
diff changeset
3652 semsg(_(e_no_white_space_allowed_before_str_str), ":", *arg);
21759
25b659fa5ca5 patch 8.2.1429: Vim9: no error for missing white after : in dict
Bram Moolenaar <Bram@vim.org>
parents: 21755
diff changeset
3653 else
25b659fa5ca5 patch 8.2.1429: Vim9: no error for missing white after : in dict
Bram Moolenaar <Bram@vim.org>
parents: 21755
diff changeset
3654 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
3655 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3656 }
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3657 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
3658 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
3659 {
23877
85cf06ddb2a8 patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23837
diff changeset
3660 semsg(_(e_white_space_required_after_str_str), ":", *arg);
21759
25b659fa5ca5 patch 8.2.1429: Vim9: no error for missing white after : in dict
Bram Moolenaar <Bram@vim.org>
parents: 21755
diff changeset
3661 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
3662 }
25b659fa5ca5 patch 8.2.1429: Vim9: no error for missing white after : in dict
Bram Moolenaar <Bram@vim.org>
parents: 21755
diff changeset
3663
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3664 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
3665 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3666 *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
3667 goto failret;
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3668 }
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3669
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3670 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
3671 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3672 if (!is_const)
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3673 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
3674 ++count;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3675
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3676 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
3677 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
3678 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3679 *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
3680 goto failret;
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3681 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3682 if (**arg == '}')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3683 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3684 if (**arg != ',')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3685 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3686 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
3687 goto failret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3688 }
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
3689 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
3690 {
23888
d95403445b6b patch 8.2.2486: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23882
diff changeset
3691 semsg(_(e_no_white_space_allowed_before_str_str), ",", whitep);
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
3692 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
3693 }
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3694 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
3695 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
3696 {
23877
85cf06ddb2a8 patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23837
diff changeset
3697 semsg(_(e_white_space_required_after_str_str), ",", *arg);
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
3698 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
3699 }
23877
85cf06ddb2a8 patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23837
diff changeset
3700 *arg = skipwhite(whitep);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3701 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3702
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3703 *arg = *arg + 1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3704
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3705 // 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
3706 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
3707 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
3708 *arg += STRLEN(*arg);
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3709
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3710 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
3711 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
3712 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
3713
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3714 failret:
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3715 if (*arg == NULL)
22508
ac8c4a8b8cba patch 8.2.1802: Vim9: crash with unterminated dict
Bram Moolenaar <Bram@vim.org>
parents: 22504
diff changeset
3716 {
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3717 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
3718 *arg = (char_u *)"";
ac8c4a8b8cba patch 8.2.1802: Vim9: crash with unterminated dict
Bram Moolenaar <Bram@vim.org>
parents: 22504
diff changeset
3719 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3720 dict_unref(d);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3721 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3722 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3723
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3724 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3725 * Compile "&option".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3726 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3727 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3728 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
3729 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3730 typval_T rettv;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3731 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
3732 int ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3733
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3734 // 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
3735 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
3736 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
3737 if (ret == OK)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3738 {
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21116
diff changeset
3739 // 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
3740 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
3741 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
3742 : 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
3743
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3744 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
3745 vim_free(name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3746 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3747 clear_tv(&rettv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3748
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3749 return ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3750 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3751
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3752 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3753 * Compile "$VAR".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3754 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3755 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3756 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
3757 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3758 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
3759 int len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3760 int ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3761 char_u *name;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3762
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3763 ++*arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3764 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
3765 if (len == 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3766 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
3767 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
3768 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3769 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3770
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21116
diff changeset
3771 // 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
3772 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
3773 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
3774 vim_free(name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3775 return ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3776 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3777
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3778 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3779 * Compile "@r".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3780 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3781 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3782 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
3783 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3784 int ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3785
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3786 ++*arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3787 if (**arg == NUL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3788 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
3789 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
3790 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3791 }
21612
c495d3e30f4b patch 8.2.1356: Vim9: cannot get the percent register
Bram Moolenaar <Bram@vim.org>
parents: 21610
diff changeset
3792 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
3793 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3794 emsg_invreg(**arg);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3795 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3796 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3797 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
3798 ++*arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3799 return ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3800 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3801
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3802 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3803 * 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
3804 * 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
3805 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3806 static int
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3807 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
3808 {
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3809 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
3810
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3811 // 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
3812 while (p > start)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3813 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3814 --p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3815 if (*p == '-' || *p == '+')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3816 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3817 // 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
3818 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3819 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
3820 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3821 if (*p == '-')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3822 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
3823 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3824 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3825 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3826 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3827 varnumber_T val;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3828 int error = FALSE;
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 // 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
3831 // here
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3832 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
3833 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3834 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
3835 clear_tv(rettv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3836 if (error)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3837 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3838 if (*p == '-')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3839 val = -val;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3840 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
3841 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
3842 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3843 }
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3844 else if (numeric_only)
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3845 {
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3846 ++p;
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3847 break;
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3848 }
22606
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
3849 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
3850 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3851 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
3852
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3853 // '!' 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
3854 clear_tv(rettv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3855 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
3856 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
3857 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3858 }
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3859 *end = p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3860 return OK;
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
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3863 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3864 * 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
3865 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3866 static void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3867 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
3868 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3869 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
3870 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3871 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
3872 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
3873 *arg += 6;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3874 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3875 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
3876 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3877 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
3878 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
3879 *arg += 7;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3880 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3881 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
3882 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3883 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
3884 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
3885 *arg += 6;
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 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
3888 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3889 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
3890 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
3891 *arg += 6;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3892 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3893 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3894
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
3895 exprtype_T
20305
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3896 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
3897 {
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
3898 exprtype_T type = EXPR_UNKNOWN;
20305
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3899 int i;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3900
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3901 switch (p[0])
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3902 {
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3903 case '=': if (p[1] == '=')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3904 type = EXPR_EQUAL;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3905 else if (p[1] == '~')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3906 type = EXPR_MATCH;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3907 break;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3908 case '!': if (p[1] == '=')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3909 type = EXPR_NEQUAL;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3910 else if (p[1] == '~')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3911 type = EXPR_NOMATCH;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3912 break;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3913 case '>': if (p[1] != '=')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3914 {
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3915 type = EXPR_GREATER;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3916 *len = 1;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3917 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3918 else
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3919 type = EXPR_GEQUAL;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3920 break;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3921 case '<': if (p[1] != '=')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3922 {
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3923 type = EXPR_SMALLER;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3924 *len = 1;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3925 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3926 else
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3927 type = EXPR_SEQUAL;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3928 break;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3929 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
3930 {
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3931 // "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
3932 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
3933 *len = 5;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3934 i = p[*len];
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3935 if (!isalnum(i) && i != '_')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3936 {
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3937 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
3938 *type_is = TRUE;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3939 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3940 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3941 break;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3942 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3943 return type;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3944 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3945
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3946 /*
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3947 * 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
3948 */
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3949 static void
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3950 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
3951 {
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3952 evalarg_T evalarg;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3953
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3954 CLEAR_FIELD(evalarg);
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3955 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
3956 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
3957 }
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3958
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3959 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3960 * 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
3961 * 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
3962 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3963 static int
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3964 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
3965 {
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3966 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
3967
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3968 // 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
3969 while (p > start)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3970 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3971 --p;
22932
87b62395a4d1 patch 8.2.2013: Vim9: not skipping white space after unary minus
Bram Moolenaar <Bram@vim.org>
parents: 22926
diff changeset
3972 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
3973 --p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3974 if (*p == '-' || *p == '+')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3975 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3976 int negate = *p == '-';
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3977 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3978
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3979 // TODO: check type
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3980 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
3981 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3982 --p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3983 if (*p == '-')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3984 negate = !negate;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3985 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3986 // 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
3987 if (negate)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3988 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
3989 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3990 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
3991 if (isn == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3992 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3993 }
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3994 else if (numeric_only)
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3995 {
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3996 ++p;
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3997 break;
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3998 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3999 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4000 {
22606
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
4001 int invert = *p == '!';
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
4002
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
4003 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
4004 {
22606
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
4005 if (p[-1] == '!')
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
4006 invert = !invert;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4007 --p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4008 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4009 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
4010 return FAIL;
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 }
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4013 *end = p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4014 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4015 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4016
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4017 /*
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4018 * Compile "(expression)": recursive!
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4019 * Return FAIL/OK.
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4020 */
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4021 static int
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4022 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
4023 {
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
4024 int ret;
23614
455ad460ff4f patch 8.2.2349: Vim9: cannot handle line break after parenthesis at line end
Bram Moolenaar <Bram@vim.org>
parents: 23586
diff changeset
4025 char_u *p = *arg + 1;
455ad460ff4f patch 8.2.2349: Vim9: cannot handle line break after parenthesis at line end
Bram Moolenaar <Bram@vim.org>
parents: 23586
diff changeset
4026
455ad460ff4f patch 8.2.2349: Vim9: cannot handle line break after parenthesis at line end
Bram Moolenaar <Bram@vim.org>
parents: 23586
diff changeset
4027 if (may_get_next_line_error(p, arg, cctx) == FAIL)
455ad460ff4f patch 8.2.2349: Vim9: cannot handle line break after parenthesis at line end
Bram Moolenaar <Bram@vim.org>
parents: 23586
diff changeset
4028 return FAIL;
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4029 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
4030 {
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4031 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
4032 }
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4033 else
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4034 {
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4035 // 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
4036 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
4037 return FAIL;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4038 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
4039 }
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
4040 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
4041 return FAIL;
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4042 if (**arg == ')')
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4043 ++*arg;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4044 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
4045 {
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4046 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
4047 ret = FAIL;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4048 }
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4049 return ret;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4050 }
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4051
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4052 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4053 * 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
4054 * 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
4055 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4056 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4057 compile_subscript(
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4058 char_u **arg,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4059 cctx_T *cctx,
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4060 char_u *start_leader,
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4061 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
4062 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
4063 {
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4064 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
4065
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4066 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4067 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
4068 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
4069
21353
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
4070 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
4071 {
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4072 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
4073
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
4074 // 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
4075 // 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
4076 // 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
4077 if (next != NULL &&
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
4078 ((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
4079 && (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
4080 || (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
4081 {
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
4082 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
4083 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
4084 return FAIL;
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4085 *arg = next;
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4086 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
4087 }
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
4088 }
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
4089
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 23199
diff changeset
4090 // 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
4091 // 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
4092 if (**arg == '(')
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4093 {
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
4094 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
4095 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
4096 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
4097
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4098 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
4099 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4100 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
4101
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4102 // 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
4103 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
4104
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4105 *arg = skipwhite(p + 1);
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
4106 if (compile_arguments(arg, cctx, &argcount, FALSE) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4107 return FAIL;
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4108 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
4109 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4110 }
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4111 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
4112 {
21465
b5d4ab124782 patch 8.2.1283: Vim9: error for misplaced -> lacks argument
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
4113 char_u *pstart = p;
b5d4ab124782 patch 8.2.1283: Vim9: error for misplaced -> lacks argument
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
4114
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4115 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
4116 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4117 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
4118
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4119 // something->method()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4120 // 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
4121 // -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
4122 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
4123 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4124
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4125 p += 2;
20949
62912ad41aff patch 8.2.1026: Vim9: cannot break the line after "->"
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
4126 *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
4127 // 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
4128 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
4129 {
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4130 int argcount = 1;
24361
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4131 garray_T *stack = &cctx->ctx_type_stack;
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4132 int type_idx_start = stack->ga_len;
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4133 type_T *type;
24361
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4134 int expr_isn_start = cctx->ctx_instr.ga_len;
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4135 int expr_isn_end;
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4136 int arg_isn_count;
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4137
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4138 // 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
4139 // or lambda: list->((arg) => expr)(arg)
24361
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4140 //
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4141 // Fist compile the function expression.
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4142 if (compile_parenthesis(arg, cctx, ppconst) == FAIL)
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4143 return FAIL;
24361
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4144
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4145 // Remember the next instruction index, where the instructions
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4146 // for arguments are being written.
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4147 expr_isn_end = cctx->ctx_instr.ga_len;
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4148
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4149 // Compile the arguments.
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4150 if (**arg != '(')
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4151 {
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
4152 if (*skipwhite(*arg) == '(')
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
4153 emsg(_(e_nowhitespace));
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
4154 else
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
4155 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
4156 return FAIL;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4157 }
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4158 *arg = skipwhite(*arg + 1);
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
4159 if (compile_arguments(arg, cctx, &argcount, FALSE) == FAIL)
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4160 return FAIL;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4161
24361
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4162 // Move the instructions for the arguments to before the
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4163 // instructions of the expression and move the type of the
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4164 // expression after the argument types. This is what ISN_PCALL
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4165 // expects.
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4166 stack = &cctx->ctx_type_stack;
24361
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4167 arg_isn_count = cctx->ctx_instr.ga_len - expr_isn_end;
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4168 if (arg_isn_count > 0)
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4169 {
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4170 int expr_isn_count = expr_isn_end - expr_isn_start;
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4171 isn_T *isn = ALLOC_MULT(isn_T, expr_isn_count);
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4172
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4173 if (isn == NULL)
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4174 return FAIL;
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4175 mch_memmove(isn, ((isn_T *)cctx->ctx_instr.ga_data)
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4176 + expr_isn_start,
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4177 sizeof(isn_T) * expr_isn_count);
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4178 mch_memmove(((isn_T *)cctx->ctx_instr.ga_data)
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4179 + expr_isn_start,
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4180 ((isn_T *)cctx->ctx_instr.ga_data) + expr_isn_end,
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4181 sizeof(isn_T) * arg_isn_count);
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4182 mch_memmove(((isn_T *)cctx->ctx_instr.ga_data)
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4183 + expr_isn_start + arg_isn_count,
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4184 isn, sizeof(isn_T) * expr_isn_count);
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4185 vim_free(isn);
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4186
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4187 type = ((type_T **)stack->ga_data)[type_idx_start];
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4188 mch_memmove(((type_T **)stack->ga_data) + type_idx_start,
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4189 ((type_T **)stack->ga_data) + type_idx_start + 1,
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4190 sizeof(type_T *)
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4191 * (stack->ga_len - type_idx_start - 1));
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4192 ((type_T **)stack->ga_data)[stack->ga_len - 1] = type;
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4193 }
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4194
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4195 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
4196 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
4197 (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
4198 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4199 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4200 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4201 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4202 // 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
4203 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
4204 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
4205 {
21465
b5d4ab124782 patch 8.2.1283: Vim9: error for misplaced -> lacks argument
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
4206 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
4207 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
4208 }
19848
36d629aa3d6e patch 8.2.0480: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19830
diff changeset
4209 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
4210 p += 2;
21650
79a8d723a3d2 patch 8.2.1375: Vim9: method name with digit not accepted
Bram Moolenaar <Bram@vim.org>
parents: 21648
diff changeset
4211 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
4212 ;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4213 if (*p != '(')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4214 {
19848
36d629aa3d6e patch 8.2.0480: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19830
diff changeset
4215 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
4216 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4217 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4218 // 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
4219 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
4220 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4221 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4222 }
21562
55aa283a0e5e patch 8.2.1331: Vim9: :echo with two lists doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21558
diff changeset
4223 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
4224 {
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4225 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
4226
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
4227 // 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
4228 // 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
4229 // string index: text[123]
24432
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
4230 // blob index: blob[123]
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
4231 // 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
4232 // 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
4233 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
4234 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4235 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
4236
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4237 ++p;
21248
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
4238 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
4239 return FAIL;
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4240 if (**arg == ':')
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4241 {
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4242 // 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
4243 generate_PUSHNR(cctx, 0);
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4244 }
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4245 else
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4246 {
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4247 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
4248 return FAIL;
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4249 if (**arg == ':')
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4250 {
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
4251 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
4252 ":", *arg);
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4253 return FAIL;
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4254 }
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
4255 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
4256 return FAIL;
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4257 *arg = skipwhite(*arg);
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4258 }
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4259 if (**arg == ':')
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4260 {
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4261 is_slice = TRUE;
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4262 ++*arg;
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4263 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
4264 {
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
4265 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
4266 ":", *arg);
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4267 return FAIL;
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4268 }
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
4269 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
4270 return FAIL;
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4271 if (**arg == ']')
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4272 // 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
4273 generate_PUSHNR(cctx, -1);
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4274 else
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4275 {
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4276 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
4277 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
4278 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
4279 return FAIL;
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4280 *arg = skipwhite(*arg);
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4281 }
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4282 }
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4283
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4284 if (**arg != ']')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4285 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4286 emsg(_(e_missbrac));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4287 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4288 }
19342
8ff84bc1c89b patch 8.2.0229: compare instructions not tested
Bram Moolenaar <Bram@vim.org>
parents: 19336
diff changeset
4289 *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
4290
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
4291 if (compile_member(is_slice, cctx) == FAIL)
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4292 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4293 }
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4294 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
4295 {
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4296 // 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
4297 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
4298 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4299 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
4300
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4301 *arg = p + 1;
24339
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 24331
diff changeset
4302 if (IS_WHITE_OR_NUL(**arg))
22482
a1b3804163ca patch 8.2.1789: Vim9: crash with invalid list constant
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
4303 {
a1b3804163ca patch 8.2.1789: Vim9: crash with invalid list constant
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
4304 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
4305 return FAIL;
22482
a1b3804163ca patch 8.2.1789: Vim9: crash with invalid list constant
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
4306 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4307 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
4308 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
4309 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
4310 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
4311 if (p == *arg)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4312 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
4313 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
4314 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4315 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
4316 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
4317 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4318 *arg = p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4319 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4320 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4321 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4322 }
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 // 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
4325 // 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
4326 // 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
4327 // 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
4328
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4329 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4330 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4331
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4332 /*
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4333 * 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
4334 * "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
4335 *
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4336 * 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
4337 * 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
4338 *
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4339 * 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
4340 */
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4343 * number number constant
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4344 * 0zFFFFFFFF Blob constant
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4345 * "string" string constant
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4346 * '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
4347 * &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
4348 * @r register contents
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4349 * identifier variable value
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4350 * function() function call
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4351 * $VAR environment variable
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4352 * (expression) nested expression
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4353 * [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
4354 * {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
4355 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4356 * Also handle:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4357 * ! 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
4358 * - 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
4359 * + 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
4360 * 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
4361 * 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
4362 * 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
4363 * 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
4364 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4365 static int
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4366 compile_expr7(
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4367 char_u **arg,
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4368 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
4369 ppconst_T *ppconst)
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
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 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
4372 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
4373 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
4374 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
4375
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4376 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
4377
19181
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 * 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
4380 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4381 start_leader = *arg;
23525
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23521
diff changeset
4382 if (eval_leader(arg, TRUE) == FAIL)
54ec7c8b7459 patch 8.2.2305: Vim9: "++var" and "--var" are silently accepted
Bram Moolenaar <Bram@vim.org>
parents: 23521
diff changeset
4383 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4384 end_leader = *arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4385
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4386 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
4387 switch (**arg)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4388 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4389 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4390 * Number constant.
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 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
4393 case '1':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4394 case '2':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4395 case '3':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4396 case '4':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4397 case '5':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4398 case '6':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4399 case '7':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4400 case '8':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4401 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
4402 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
4403 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
4404 // 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
4405 // 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
4406 // '!'.
a7e0091a4669 patch 8.2.1421: Vim9: handling "+" and "-" before number differs from script
Bram Moolenaar <Bram@vim.org>
parents: 21739
diff changeset
4407 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
4408 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
4409 {
a7e0091a4669 patch 8.2.1421: Vim9: handling "+" and "-" before number differs from script
Bram Moolenaar <Bram@vim.org>
parents: 21739
diff changeset
4410 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
4411 return FAIL;
a7e0091a4669 patch 8.2.1421: Vim9: handling "+" and "-" before number differs from script
Bram Moolenaar <Bram@vim.org>
parents: 21739
diff changeset
4412 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4413 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4414
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4415 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4416 * String constant: "string".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4417 */
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21116
diff changeset
4418 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
4419 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4420 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4421
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4422 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4423 * 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
4424 */
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21116
diff changeset
4425 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
4426 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4427 break;
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4430 * Constant Vim variable.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4431 */
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4432 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
4433 ret = NOTDONE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4434 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4435
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4436 /*
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4437 * "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
4438 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4439 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
4440 && !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
4441 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4442 *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
4443 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
4444 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
4445 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4446 else
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4447 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
4448 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4449
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4450 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4451 * "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
4452 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4453 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
4454 && !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
4455 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4456 *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
4457 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
4458 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
4459 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4460 else
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4461 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
4462 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4463
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4464 /*
23497
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4465 * "null" constant
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4466 */
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4467 case 'n': if (STRNCMP(*arg, "null", 4) == 0
24087
92139c21cdfd patch 8.2.2585: Vim9: illegal memory access
Bram Moolenaar <Bram@vim.org>
parents: 24085
diff changeset
4468 && !eval_isnamec((*arg)[4]))
23497
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4469 {
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4470 *arg += 4;
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4471 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
4472 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
4473 }
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4474 else
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4475 ret = NOTDONE;
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4476 break;
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4477
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4478 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4479 * List: [expr, expr]
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4480 */
23806
c0f2c6c56147 patch 8.2.2444: Vim9: compile error with combination of operator and list
Bram Moolenaar <Bram@vim.org>
parents: 23735
diff changeset
4481 case '[': if (generate_ppconst(cctx, ppconst) == FAIL)
c0f2c6c56147 patch 8.2.2444: Vim9: compile error with combination of operator and list
Bram Moolenaar <Bram@vim.org>
parents: 23735
diff changeset
4482 return FAIL;
c0f2c6c56147 patch 8.2.2444: Vim9: compile error with combination of operator and list
Bram Moolenaar <Bram@vim.org>
parents: 23735
diff changeset
4483 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
4484 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4485
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 * 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
4488 */
23806
c0f2c6c56147 patch 8.2.2444: Vim9: compile error with combination of operator and list
Bram Moolenaar <Bram@vim.org>
parents: 23735
diff changeset
4489 case '{': if (generate_ppconst(cctx, ppconst) == FAIL)
c0f2c6c56147 patch 8.2.2444: Vim9: compile error with combination of operator and list
Bram Moolenaar <Bram@vim.org>
parents: 23735
diff changeset
4490 return FAIL;
c0f2c6c56147 patch 8.2.2444: Vim9: compile error with combination of operator and list
Bram Moolenaar <Bram@vim.org>
parents: 23735
diff changeset
4491 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
4492 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4493
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4494 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4495 * Option value: &name
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4496 */
21903
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4497 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
4498 return FAIL;
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4499 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
4500 break;
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4503 * Environment variable: $VAR.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4504 */
21903
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4505 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
4506 return FAIL;
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4507 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
4508 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4509
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4510 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4511 * Register contents: @r.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4512 */
21903
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4513 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
4514 return FAIL;
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4515 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
4516 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4517 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4518 * 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
4519 * 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
4520 * 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
4521 */
23368
a7cbdb9294c4 patch 8.2.2227: Vim9: recognizing lambda is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 23364
diff changeset
4522 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
4523 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
4524 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
4525 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
4526 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4527
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4528 default: ret = NOTDONE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4529 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4530 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4531 if (ret == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4532 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4533
20336
2fd980fb9ab3 patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents: 20334
diff changeset
4534 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
4535 {
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
4536 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
4537 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
4538 else
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4539 // 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
4540 // 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
4541 ++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
4542 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4543 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
4544 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4545 char_u *p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4546 int r;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4547
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4548 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
4549 {
24158
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
4550 if (!vim9_bad_comment(*arg))
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
4551 {
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
4552 if (ends_excmd(*skipwhite(*arg)))
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
4553 semsg(_(e_empty_expression_str), *arg);
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
4554 else
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
4555 semsg(_(e_name_expected_str), *arg);
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
4556 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4557 return FAIL;
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
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4560 // "name" or "name()"
19583
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
4561 p = to_name_end(*arg, TRUE);
24408
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
4562 if (p - *arg == (size_t)1 && **arg == '_')
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
4563 {
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
4564 emsg(_(e_cannot_use_underscore_here));
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
4565 return FAIL;
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
4566 }
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
4567
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4568 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
4569 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4570 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
4571 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4572 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
4573 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4574 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
4575 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
4576 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
4577 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4578 if (r == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4579 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4580 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4581
20322
a3e78893a90b patch 8.2.0716: Vim9: another memory leak
Bram Moolenaar <Bram@vim.org>
parents: 20320
diff changeset
4582 // Handle following "[]", ".member", etc.
a3e78893a90b patch 8.2.0716: Vim9: another memory leak
Bram Moolenaar <Bram@vim.org>
parents: 20320
diff changeset
4583 // 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
4584 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
4585 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
4586 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
4587 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
4588 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4589 // 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
4590 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
4591 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
4592 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
4593 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
4594 }
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4595 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
4596 return FAIL;
20322
a3e78893a90b patch 8.2.0716: Vim9: another memory leak
Bram Moolenaar <Bram@vim.org>
parents: 20320
diff changeset
4597 return OK;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4598 }
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 /*
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4601 * 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
4602 */
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4603 void
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4604 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
4605 {
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4606 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
4607
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4608 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
4609 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
4610 }
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4611
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4612 /*
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4613 * <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
4614 */
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4615 static int
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4616 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
4617 {
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4618 type_T *want_type = NULL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4619
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4620 // Recognize <type>
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4621 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
4622 {
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4623 ++*arg;
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
4624 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
4625 if (want_type == NULL)
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4626 return FAIL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4627
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4628 if (**arg != '>')
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4629 {
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4630 if (*skipwhite(*arg) == '>')
23888
d95403445b6b patch 8.2.2486: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23882
diff changeset
4631 semsg(_(e_no_white_space_allowed_before_str_str), ">", *arg);
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4632 else
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
4633 emsg(_(e_missing_gt));
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4634 return FAIL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4635 }
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4636 ++*arg;
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
4637 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
4638 return FAIL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4639 }
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4640
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4641 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
4642 return FAIL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4643
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4644 if (want_type != NULL)
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4645 {
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4646 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
4647 type_T *actual;
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
4648 where_T where;
21811
3261e28c638a patch 8.2.1455: Vim9: crash when using typecast before constant
Bram Moolenaar <Bram@vim.org>
parents: 21809
diff changeset
4649
3261e28c638a patch 8.2.1455: Vim9: crash when using typecast before constant
Bram Moolenaar <Bram@vim.org>
parents: 21809
diff changeset
4650 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
4651 actual = ((type_T **)stack->ga_data)[stack->ga_len - 1];
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
4652 where.wt_index = 0;
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
4653 where.wt_variable = FALSE;
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
4654 if (check_type(want_type, actual, FALSE, where) == FAIL)
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4655 {
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
4656 if (need_type(actual, want_type, -1, 0, cctx, FALSE, FALSE) == FAIL)
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4657 return FAIL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4658 }
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4659 }
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4660
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4661 return OK;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4662 }
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4663
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4664 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4665 * * number multiplication
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4666 * / number division
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4667 * % number modulo
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4668 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4669 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
4670 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
4671 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4672 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
4673 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
4674 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
4675
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4676 // get the first expression
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4677 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
4678 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4679
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4680 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4681 * 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
4682 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4683 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4684 {
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4685 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
4686 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
4687 break;
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4688 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
4689 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4690 *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
4691 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
4692 }
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4693
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4694 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
4695 {
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4696 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
4697 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4698 }
23106
b0c88aa0175b patch 8.2.2099: Vim9: some checks are not tested
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
4699 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
4700 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4701
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4702 // get the second expression
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4703 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
4704 return FAIL;
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4705
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4706 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
4707 && 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
4708 && 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
4709 {
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23669
diff changeset
4710 typval_T *tv1 = &ppconst->pp_tv[ppconst_used];
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23669
diff changeset
4711 typval_T *tv2 = &ppconst->pp_tv[ppconst_used + 1];
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23669
diff changeset
4712 varnumber_T res = 0;
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23669
diff changeset
4713 int failed = FALSE;
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4714
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4715 // 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
4716 switch (*op)
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4717 {
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4718 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
4719 break;
23669
cf2904dd9691 patch 8.2.2376: Vim9: crash when dividing by zero in compiled code
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
4720 case '/': res = num_divide(tv1->vval.v_number,
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23669
diff changeset
4721 tv2->vval.v_number, &failed);
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4722 break;
23669
cf2904dd9691 patch 8.2.2376: Vim9: crash when dividing by zero in compiled code
Bram Moolenaar <Bram@vim.org>
parents: 23662
diff changeset
4723 case '%': res = num_modulus(tv1->vval.v_number,
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23669
diff changeset
4724 tv2->vval.v_number, &failed);
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4725 break;
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4726 }
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23669
diff changeset
4727 if (failed)
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23669
diff changeset
4728 return FAIL;
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4729 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
4730 --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
4731 }
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4732 else
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4733 {
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4734 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
4735 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
4736 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4737 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4738
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4739 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4740 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4741
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4742 /*
24085
23c692a4bc36 patch 8.2.2584: Vim9: type error for assigning "any" to a list
Bram Moolenaar <Bram@vim.org>
parents: 24067
diff changeset
4743 * + number addition or list/blobl concatenation
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4744 * - number subtraction
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4745 * .. string concatenation
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4746 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4747 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
4748 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
4749 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4750 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
4751 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
4752 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
4753 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
4754
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4755 // 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
4756 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
4757 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4758
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4759 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4760 * 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
4761 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4762 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4763 {
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4764 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
4765 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
4766 break;
24533
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
4767 if (op[0] == op[1] && *op != '.' && next)
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
4768 // Finding "++" or "--" on the next line is a separate command.
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
4769 // But ".." is concatenation.
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
4770 break;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4771 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
4772 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
4773 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4774 *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
4775 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
4776 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4777
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4778 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
4779 {
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4780 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
4781 return FAIL;
19181
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
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
4784 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
4785 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4786
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4787 // 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
4788 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
4789 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
4790
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4791 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
4792 && (*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
4793 ? (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
4794 && 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
4795 : (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
4796 && 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
4797 {
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4798 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
4799 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
4800
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4801 // 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
4802 if (*op == '+')
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4803 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
4804 else if (*op == '-')
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4805 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
4806 else
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4807 {
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4808 // concatenate constant strings
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4809 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
4810 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
4811 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
4812
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4813 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
4814 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
4815 {
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4816 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
4817 return FAIL;
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4818 }
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4819 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
4820 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
4821 vim_free(s1);
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4822 vim_free(s2);
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4823 }
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4824 --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
4825 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4826 else
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4827 {
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4828 generate_ppconst(cctx, ppconst);
24085
23c692a4bc36 patch 8.2.2584: Vim9: type error for assigning "any" to a list
Bram Moolenaar <Bram@vim.org>
parents: 24067
diff changeset
4829 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
4830 if (*op == '.')
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4831 {
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4832 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
4833 || 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
4834 return FAIL;
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4835 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
4836 }
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4837 else
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4838 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
4839 }
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4840 }
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4841
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4842 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4843 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4844
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4845 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4846 * expr5a == expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4847 * expr5a =~ expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4848 * expr5a != expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4849 * expr5a !~ expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4850 * expr5a > expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4851 * expr5a >= expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4852 * expr5a < expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4853 * expr5a <= expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4854 * expr5a is expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4855 * expr5a isnot expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4856 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4857 * Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4858 * 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
4859 * 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
4860 * 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
4861 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4862 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
4863 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
4864 {
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
4865 exprtype_T type = EXPR_UNKNOWN;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4866 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
4867 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
4868 int len = 2;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4869 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
4870 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
4871
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4872 // 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
4873 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
4874 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4875
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4876 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
4877 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
4878
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4879 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4880 * 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
4881 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4882 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
4883 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4884 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
4885
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4886 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
4887 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4888 *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
4889 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
4890 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4891 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
4892 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4893 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
4894 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4895 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4896 // 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
4897 if (p[len] == '?')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4898 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4899 ic = TRUE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4900 ++len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4901 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4902 // 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
4903 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
4904 ++len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4905 // 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
4906
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4907 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
4908 {
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4909 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
4910 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4911 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4912
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4913 // 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
4914 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
4915 return FAIL;
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4916
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4917 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
4918 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4919
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4920 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
4921 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4922 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
4923 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
4924 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
4925
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4926 // 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
4927 // 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
4928 // 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
4929 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
4930 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
4931 else
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4932 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4933 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
4934 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
4935 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
4936 ? 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
4937 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
4938 --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
4939 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4940 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
4941 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4942
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4943 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
4944 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
4945 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4946
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4947 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4948 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4949
20334
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
4950 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
4951
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4952 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4953 * Compile || or &&.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4954 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4955 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
4956 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
4957 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
4958 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
4959 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
4960 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
4961 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
4962 {
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4963 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
4964 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
4965 int opchar = *op;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4966
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4967 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
4968 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4969 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
4970 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
4971
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4972 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4973 * 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
4974 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4975 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
4976 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
4977 {
24331
bd010982f0be patch 8.2.2706: Vim9: wrong line number reported for boolean operator
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
4978 long start_lnum = SOURCING_LNUM;
bd010982f0be patch 8.2.2706: Vim9: wrong line number reported for boolean operator
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
4979 int start_ctx_lnum = cctx->ctx_lnum;
bd010982f0be patch 8.2.2706: Vim9: wrong line number reported for boolean operator
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
4980 int save_lnum;
bd010982f0be patch 8.2.2706: Vim9: wrong line number reported for boolean operator
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
4981
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4982 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
4983 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4984 *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
4985 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
4986 }
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4987
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4988 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
4989 {
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
4990 semsg(_(e_white_space_required_before_and_after_str_at_str),
24339
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 24331
diff changeset
4991 op, p);
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4992 return FAIL;
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4993 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4994
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
4995 // 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
4996 // 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
4997 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
4998
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
4999 // Every part must evaluate to a bool.
24331
bd010982f0be patch 8.2.2706: Vim9: wrong line number reported for boolean operator
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
5000 SOURCING_LNUM = start_lnum;
bd010982f0be patch 8.2.2706: Vim9: wrong line number reported for boolean operator
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
5001 save_lnum = cctx->ctx_lnum;
bd010982f0be patch 8.2.2706: Vim9: wrong line number reported for boolean operator
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
5002 cctx->ctx_lnum = start_ctx_lnum;
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
5003 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
5004 {
24331
bd010982f0be patch 8.2.2706: Vim9: wrong line number reported for boolean operator
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
5005 cctx->ctx_lnum = save_lnum;
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
5006 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
5007 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
5008 }
24331
bd010982f0be patch 8.2.2706: Vim9: wrong line number reported for boolean operator
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
5009 cctx->ctx_lnum = save_lnum;
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
5010
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5011 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
5012 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5013 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
5014 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5015 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5016 *(((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
5017 ++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
5018 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
5019 ? 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
5020
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5021 // 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
5022 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
5023 {
545ff3b4543c patch 8.2.2101: Vim9: memory leak when literal dict has an error
Bram Moolenaar <Bram@vim.org>
parents: 23106
diff changeset
5024 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
5025 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
5026 }
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
5027
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5028 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
5029 : 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
5030 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5031 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
5032 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5033 }
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
5034
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
5035 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
5036 }
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5037 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
5038
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
5039 // 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
5040 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
5041 {
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
5042 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
5043 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
5044 }
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
5045
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5046 // 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
5047 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
5048 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5049 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5050
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5051 --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
5052 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
5053 + *(((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
5054 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
5055 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5056 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
5057 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5058
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5059 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5060 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5061
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5062 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5063 * 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
5064 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5065 * Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5066 * 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
5067 * 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
5068 * 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
5069 * 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
5070 * 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
5071 * 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
5072 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5073 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5074 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
5075 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
5076 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5077 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
5078
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5079 // 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
5080 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
5081 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5082
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5083 // || 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
5084 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
5085 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5086
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5087 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5088 * 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
5089 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5090 * Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5091 * 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
5092 * 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
5093 * 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
5094 * 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
5095 * 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
5096 * 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
5097 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5098 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5099 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
5100 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
5101 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5102 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
5103
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5104 // 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
5105 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
5106 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5107
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5108 // || 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
5109 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
5110 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5111
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5112 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5113 * 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
5114 * Produces instructions:
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5115 * 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
5116 * 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
5117 * EVAL expr1a
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5118 * JUMP_ALWAYS end
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5119 * alt: EVAL expr1b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5120 * end:
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5121 *
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5122 * Toplevel expression: expr2 ?? expr1
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5123 * Produces instructions:
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5124 * EVAL expr2 Push result of "expr2"
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5125 * 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
5126 * EVAL expr1
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5127 * end:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5128 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5129 static int
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
5130 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
5131 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5132 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
5133 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
5134 char_u *next;
20305
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
5135
21957
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
5136 // 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
5137 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
5138 {
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
5139 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
5140 return OK;
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
5141 }
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
5142
20305
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
5143 // 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
5144 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
5145 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5146
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
5147 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
5148 if (*p == '?')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5149 {
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5150 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
5151 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
5152 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
5153 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
5154 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
5155 isn_T *isn;
20966
0ee7de260208 patch 8.2.1034: compiler warning for uninitialized variables
Bram Moolenaar <Bram@vim.org>
parents: 20961
diff changeset
5156 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
5157 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
5158 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
5159 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
5160
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
5161 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
5162 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
5163 *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
5164 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
5165 }
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
5166
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5167 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
5168 {
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
5169 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
5170 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
5171 return FAIL;
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
5172 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5173
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5174 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
5175 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5176 // 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
5177 // 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
5178 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
5179 if (op_falsy)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5180 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
5181 else
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5182 {
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5183 int error = FALSE;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5184
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5185 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
5186 &error);
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5187 if (error)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5188 return FAIL;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5189 }
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5190 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
5191 (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
5192
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5193 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
5194 // "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
5195 generate_ppconst(cctx, ppconst);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5196 else
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5197 {
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5198 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
5199 --ppconst->pp_used;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5200 }
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5201 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5202 else
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5203 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5204 generate_ppconst(cctx, ppconst);
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5205 if (op_falsy)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5206 end_idx = instr->ga_len;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5207 generate_JUMP(cctx, op_falsy
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5208 ? 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
5209 if (op_falsy)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5210 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
5211 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5212
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5213 // 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
5214 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
5215 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
5216 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
5217 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5218
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5219 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
5220 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5221 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
5222
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5223 if (!op_falsy)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5224 {
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5225 // remember the type and drop it
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5226 --stack->ga_len;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5227 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
5228
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5229 end_idx = instr->ga_len;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5230 generate_JUMP(cctx, JUMP_ALWAYS, 0);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5231
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5232 // jump here from JUMP_IF_FALSE
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5233 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
5234 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
5235 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5236 }
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5237
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5238 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
5239 {
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5240 // Check for the ":".
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5241 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
5242 if (*p != ':')
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5243 {
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5244 emsg(_(e_missing_colon));
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5245 return FAIL;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5246 }
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5247 if (next != NULL)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5248 {
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5249 *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
5250 p = skipwhite(*arg);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5251 }
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5252
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5253 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
5254 {
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
5255 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
5256 ":", p);
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5257 return FAIL;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5258 }
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5259
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5260 // evaluate the third expression
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5261 if (has_const_expr)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5262 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
5263 ? 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
5264 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
5265 return FAIL;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5266 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
5267 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
5268 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5269
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5270 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
5271 {
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5272 type_T **typep;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5273
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5274 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
5275
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5276 // 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
5277 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
5278 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
5279
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5280 // 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
5281 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
5282 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
5283 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5284
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5285 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
5286 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5287 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
5288 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5289
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5290 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5291 * Toplevel expression.
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5292 * 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
5293 * 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
5294 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5295 static int
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5296 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
5297 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5298 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
5299
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5300 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
5301 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
5302 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5303 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
5304 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
5305 }
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5306 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
5307 *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
5308 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
5309 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5310 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5311 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5312
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5313 /*
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5314 * Toplevel expression.
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5315 */
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5316 static int
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5317 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
5318 {
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5319 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
5320 }
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5321
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5322 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5323 * compile "return [expr]"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5324 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5325 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
5326 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
5327 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5328 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
5329 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
5330 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
5331
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5332 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
5333 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5334 // 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
5335 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
5336 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5337
22926
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5338 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
5339 {
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5340 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
5341 if (check_return_type && (cctx->ctx_ufunc->uf_ret_type == NULL
23531
f39a18a42aed patch 8.2.2308: Vim9: no error when assigning lambda to funcref
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
5342 || cctx->ctx_ufunc->uf_ret_type == &t_unknown
f39a18a42aed patch 8.2.2308: Vim9: no error when assigning lambda to funcref
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
5343 || cctx->ctx_ufunc->uf_ret_type == &t_any))
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
5344 {
22926
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5345 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
5346 }
22926
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5347 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
5348 {
22926
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5349 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
5350 && 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
5351 && 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
5352 {
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5353 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
5354 return NULL;
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5355 }
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5356 if (need_type(stack_type, cctx->ctx_ufunc->uf_ret_type, -1,
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
5357 0, cctx, FALSE, FALSE) == FAIL)
22926
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5358 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
5359 }
1a393685e7ce patch 8.2.1131: Vim9: error message for returning a value is not clear
Bram Moolenaar <Bram@vim.org>
parents: 21158
diff changeset
5360 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5361 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5362 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5363 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
5364 // "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
5365 // 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
5366 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
5367 && 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
5368 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5369 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
5370 return NULL;
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
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5373 // 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
5374 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
5375 }
23586
8c5374ec8a3d patch 8.2.2335: Vim9: "silent return" does not restore command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 23578
diff changeset
5376
8c5374ec8a3d patch 8.2.2335: Vim9: "silent return" does not restore command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 23578
diff changeset
5377 // Undo any command modifiers.
8c5374ec8a3d patch 8.2.2335: Vim9: "silent return" does not restore command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 23578
diff changeset
5378 generate_undo_cmdmods(cctx);
8c5374ec8a3d patch 8.2.2335: Vim9: "silent return" does not restore command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 23578
diff changeset
5379
22926
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5380 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
5381 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5382
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5383 // "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
5384 return skipwhite(p);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5385 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5386
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5387 /*
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5388 * 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
5389 * 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
5390 * 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
5391 */
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5392 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
5393 exarg_getline(
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5394 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
5395 void *cookie,
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5396 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
5397 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
5398 {
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5399 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
5400 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
5401
a427f5f26419 patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents: 21881
diff changeset
5402 for (;;)
a427f5f26419 patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents: 21881
diff changeset
5403 {
22423
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22415
diff changeset
5404 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
5405 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
5406 ++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
5407 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
5408 // 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
5409 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
5410 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
5411 }
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5412 }
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5413
24188
c20e763bc73c patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents: 24158
diff changeset
5414 void
c20e763bc73c patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents: 24158
diff changeset
5415 fill_exarg_from_cctx(exarg_T *eap, cctx_T *cctx)
c20e763bc73c patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents: 24158
diff changeset
5416 {
c20e763bc73c patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents: 24158
diff changeset
5417 eap->getline = exarg_getline;
c20e763bc73c patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents: 24158
diff changeset
5418 eap->cookie = cctx;
c20e763bc73c patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents: 24158
diff changeset
5419 }
c20e763bc73c patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents: 24158
diff changeset
5420
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5421 /*
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5422 * 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
5423 */
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5424 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
5425 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
5426 {
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5427 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
5428 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
5429 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
5430 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
5431 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
5432 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
5433
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
5434 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
5435 {
f9b4576a618b patch 8.2.1657: Vim9: no proper error for nested ":def!"
Bram Moolenaar <Bram@vim.org>
parents: 22196
diff changeset
5436 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
5437 return NULL;
f9b4576a618b patch 8.2.1657: Vim9: no proper error for nested ":def!"
Bram Moolenaar <Bram@vim.org>
parents: 22196
diff changeset
5438 }
f9b4576a618b patch 8.2.1657: Vim9: no proper error for nested ":def!"
Bram Moolenaar <Bram@vim.org>
parents: 22196
diff changeset
5439
22973
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5440 if (*name_start == '/')
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5441 {
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5442 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
5443 if (*name_end == '/')
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5444 ++name_end;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5445 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
5446 }
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5447 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
5448 {
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5449 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
5450 {
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5451 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
5452 return NULL;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5453 }
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5454
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5455 // "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
5456 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
5457 return NULL;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5458 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
5459 }
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5460
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
5461 // 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
5462 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
5463 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5464 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
5465 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
5466 }
24033
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
5467 if (check_defined(name_start, name_end - name_start, cctx, FALSE) == FAIL)
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
5468 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
5469
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5470 eap->arg = name_end;
24188
c20e763bc73c patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents: 24158
diff changeset
5471 fill_exarg_from_cctx(eap, cctx);
c20e763bc73c patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents: 24158
diff changeset
5472
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5473 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
5474 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
5475 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
5476 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
5477 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
5478
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20419
diff changeset
5479 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
5480 {
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
5481 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
5482 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
5483 }
24152
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5484
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5485 // copy over the block scope IDs before compiling
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5486 if (!is_global && cctx->ctx_ufunc->uf_block_depth > 0)
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5487 {
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5488 int block_depth = cctx->ctx_ufunc->uf_block_depth;
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5489
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5490 ufunc->uf_block_ids = ALLOC_MULT(int, block_depth);
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5491 if (ufunc->uf_block_ids != NULL)
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5492 {
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5493 mch_memmove(ufunc->uf_block_ids, cctx->ctx_ufunc->uf_block_ids,
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5494 sizeof(int) * block_depth);
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5495 ufunc->uf_block_depth = block_depth;
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5496 }
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5497 }
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5498
23735
7caffd835aa1 patch 8.2.2409: Vim9: profiling only works for one function
Bram Moolenaar <Bram@vim.org>
parents: 23729
diff changeset
5499 if (func_needs_compiling(ufunc, PROFILING(ufunc))
7caffd835aa1 patch 8.2.2409: Vim9: profiling only works for one function
Bram Moolenaar <Bram@vim.org>
parents: 23729
diff changeset
5500 && compile_def_function(ufunc, TRUE, PROFILING(ufunc), cctx)
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
5501 == FAIL)
22369
62192fd08e0e patch 8.2.1733: Vim9: memory leaks when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
5502 {
62192fd08e0e patch 8.2.1733: Vim9: memory leaks when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
5503 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
5504 goto theend;
22369
62192fd08e0e patch 8.2.1733: Vim9: memory leaks when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
5505 }
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5506
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5507 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
5508 {
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5509 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
5510 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
5511
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5512 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
5513 r = FAIL;
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5514 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
5515 {
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
5516 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
5517 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
5518 }
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5519 }
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5520 else
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5521 {
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5522 // 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
5523 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
5524 TRUE, ufunc->uf_func_type);
22537
9870e8b6ed78 patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Bram Moolenaar <Bram@vim.org>
parents: 22508
diff changeset
5525
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
5526 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
5527 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
5528 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
5529 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
5530 r = generate_STORE(cctx, ISN_STORE, lvar->lv_idx, NULL);
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5531 }
20305
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
5532 // 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
5533
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
5534 theend:
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
5535 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
5536 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
5537 }
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5538
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5539 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5540 * 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
5541 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5542 int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5543 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
5544 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5545 if (*p == '=')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5546 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5547 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
5548 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5549 *heredoc = TRUE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5550 return 3;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5551 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5552 return 1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5553 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5554 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
5555 return 2;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5556 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
5557 return 3;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5558 return 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5559 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5560
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5561 // 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
5562 static char *reserved[] = {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5563 "true",
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5564 "false",
23497
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
5565 "null",
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5566 NULL
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5567 };
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5568
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5569 /*
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5570 * 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
5571 */
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5572 static void
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5573 generate_loadvar(
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5574 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
5575 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
5576 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
5577 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
5578 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
5579 {
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5580 switch (dest)
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5581 {
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5582 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
5583 // 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
5584 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
5585 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5586 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
5587 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
5588 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
5589 else
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
5590 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
5591 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5592 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
5593 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
5594 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5595 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
5596 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
5597 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5598 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
5599 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
5600 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5601 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
5602 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
5603 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
5604 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5605 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
5606 // 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
5607 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
5608 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5609 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
5610 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
5611 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5612 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
5613 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
5614 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5615 case dest_local:
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5616 if (lvar->lv_from_outer > 0)
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5617 generate_LOADOUTER(cctx, lvar->lv_idx, lvar->lv_from_outer,
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5618 type);
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5619 else
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5620 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
5621 break;
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5622 case dest_expr:
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5623 // 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
5624 break;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5625 }
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5626 }
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5627
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5628 /*
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5629 * 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
5630 * 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
5631 */
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5632 static char_u *
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5633 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
5634 {
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5635 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
5636
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5637 if (*p == '[')
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5638 {
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5639 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
5640 (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
5641 p = skipwhite(p);
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5642 if (*p == ']')
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5643 return p + 1;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5644 return p;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5645 }
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5646 // if (*p == '.')
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5647 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
5648 }
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5649
20953
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5650 void
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5651 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
5652 {
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5653 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
5654
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5655 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
5656 {
20961
0e01976dfd3b patch 8.2.1032: error message for declaring a variable cannot be translated
Bram Moolenaar <Bram@vim.org>
parents: 20955
diff changeset
5657 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
5658 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
5659 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
5660 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
5661 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
5662 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
5663 return;
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5664 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
5665 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
5666 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
5667 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
5668 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
5669 }
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
5670 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
5671 }
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5672
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5673 /*
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5674 * 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
5675 * 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
5676 * 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
5677 * 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
5678 * "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
5679 * 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
5680 */
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5681 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
5682 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
5683 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
5684 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
5685 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
5686 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
5687 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
5688 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
5689 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
5690 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5691 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
5692
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5693 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
5694 {
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5695 int cc;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5696 long numval;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5697 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
5698
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5699 *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
5700 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
5701 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5702 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
5703 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
5704 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5705 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
5706 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
5707 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
5708 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5709 // 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
5710 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
5711 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
5712 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5713 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
5714 *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
5715 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
5716 &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
5717 *p = cc;
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5718 switch (opt_type)
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5719 {
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5720 case gov_unknown:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5721 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
5722 return FAIL;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5723 case gov_string:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5724 case gov_hidden_string:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5725 *type = &t_string;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5726 break;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5727 case gov_bool:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5728 case gov_hidden_bool:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5729 *type = &t_bool;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5730 break;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5731 case gov_number:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5732 case gov_hidden_number:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5733 *type = &t_number;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5734 break;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5735 }
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5736 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5737 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
5738 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5739 *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
5740 *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
5741 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5742 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
5743 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5744 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
5745 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5746 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
5747 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
5748 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5749 *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
5750 *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
5751 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5752 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
5753 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5754 *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
5755 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5756 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
5757 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5758 *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
5759 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5760 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
5761 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5762 *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
5763 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5764 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
5765 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5766 *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
5767 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5768 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
5769 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5770 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
5771 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
5772
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5773 *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
5774 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
5775 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5776 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
5777 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
5778 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5779 // 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
5780 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
5781 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
5782 *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
5783 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
5784 *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
5785 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5786 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
5787 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5788
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5789 /*
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5790 * 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
5791 * 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
5792 */
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5793 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
5794 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
5795 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
5796 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
5797 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
5798 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
5799 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
5800 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
5801 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
5802 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
5803 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5804 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
5805 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5806 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
5807 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
5808 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
5809 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
5810 // 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
5811 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
5812 ? 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
5813 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
5814 // 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
5815 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
5816 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
5817 // 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
5818 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
5819 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
5820 // 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
5821 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
5822 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
5823 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
5824 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
5825 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
5826 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
5827 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
5828 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
5829 if (scriptvar_idx < 0)
24377
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24363
diff changeset
5830 // "s:" may be included in the name.
f9f8cceaece3 patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Bram Moolenaar <Bram@vim.org>
parents: 24363
diff changeset
5831 return generate_OLDSCRIPT(cctx, ISN_STORES, 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
5832 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
5833 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
5834 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
5835 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
5836 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
5837 // 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
5838 break;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5839 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5840 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
5841 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5842
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5843 static int
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5844 generate_store_lhs(cctx_T *cctx, lhs_T *lhs, int instr_count)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5845 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5846 if (lhs->lhs_dest != dest_local)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5847 return generate_store_var(cctx, lhs->lhs_dest,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5848 lhs->lhs_opt_flags, lhs->lhs_vimvaridx,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5849 lhs->lhs_scriptvar_idx, lhs->lhs_scriptvar_sid,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5850 lhs->lhs_type, lhs->lhs_name);
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5851
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5852 if (lhs->lhs_lvar != NULL)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5853 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5854 garray_T *instr = &cctx->ctx_instr;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5855 isn_T *isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5856
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5857 // optimization: turn "var = 123" from ISN_PUSHNR + ISN_STORE into
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5858 // ISN_STORENR
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5859 if (lhs->lhs_lvar->lv_from_outer == 0
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5860 && instr->ga_len == instr_count + 1
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5861 && isn->isn_type == ISN_PUSHNR)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5862 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5863 varnumber_T val = isn->isn_arg.number;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5864 garray_T *stack = &cctx->ctx_type_stack;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5865
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5866 isn->isn_type = ISN_STORENR;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5867 isn->isn_arg.storenr.stnr_idx = lhs->lhs_lvar->lv_idx;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5868 isn->isn_arg.storenr.stnr_val = val;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5869 if (stack->ga_len > 0)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5870 --stack->ga_len;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5871 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5872 else if (lhs->lhs_lvar->lv_from_outer > 0)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5873 generate_STOREOUTER(cctx, lhs->lhs_lvar->lv_idx,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5874 lhs->lhs_lvar->lv_from_outer);
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5875 else
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5876 generate_STORE(cctx, ISN_STORE, lhs->lhs_lvar->lv_idx, NULL);
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5877 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5878 return OK;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5879 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5880
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5881 static int
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5882 is_decl_command(int cmdidx)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5883 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5884 return cmdidx == CMD_let || cmdidx == CMD_var
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5885 || cmdidx == CMD_final || cmdidx == CMD_const;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5886 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5887
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5888 /*
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5889 * Figure out the LHS type and other properties for an assignment or one item
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5890 * of ":unlet" with an index.
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5891 * Returns OK or FAIL.
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5892 */
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5893 static int
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5894 compile_lhs(
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5895 char_u *var_start,
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5896 lhs_T *lhs,
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5897 int cmdidx,
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5898 int heredoc,
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5899 int oplen,
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5900 cctx_T *cctx)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5901 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5902 char_u *var_end;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5903 int is_decl = is_decl_command(cmdidx);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5904
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5905 CLEAR_POINTER(lhs);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5906 lhs->lhs_dest = dest_local;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5907 lhs->lhs_vimvaridx = -1;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5908 lhs->lhs_scriptvar_idx = -1;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5909
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5910 // "dest_end" is the end of the destination, including "[expr]" or
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5911 // ".name".
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5912 // "var_end" is the end of the variable/option/etc. name.
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5913 lhs->lhs_dest_end = skip_var_one(var_start, FALSE);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5914 if (*var_start == '@')
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5915 var_end = var_start + 2;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5916 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5917 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5918 // skip over the leading "&", "&l:", "&g:" and "$"
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5919 var_end = skip_option_env_lead(var_start);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5920 var_end = to_name_end(var_end, TRUE);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5921 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5922
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5923 // "a: type" is declaring variable "a" with a type, not dict "a:".
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5924 if (is_decl && lhs->lhs_dest_end == var_start + 2
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5925 && lhs->lhs_dest_end[-1] == ':')
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5926 --lhs->lhs_dest_end;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5927 if (is_decl && var_end == var_start + 2 && var_end[-1] == ':')
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5928 --var_end;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5929
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5930 // compute the length of the destination without "[expr]" or ".name"
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5931 lhs->lhs_varlen = var_end - var_start;
24512
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
5932 lhs->lhs_varlen_total = lhs->lhs_varlen;
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5933 lhs->lhs_name = vim_strnsave(var_start, lhs->lhs_varlen);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5934 if (lhs->lhs_name == NULL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5935 return FAIL;
23578
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
5936
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
5937 if (lhs->lhs_dest_end > var_start + lhs->lhs_varlen)
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
5938 // Something follows after the variable: "var[idx]" or "var.key".
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
5939 lhs->lhs_has_index = TRUE;
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
5940
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5941 if (heredoc)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5942 lhs->lhs_type = &t_list_string;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5943 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5944 lhs->lhs_type = &t_any;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5945
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5946 if (cctx->ctx_skip != SKIP_YES)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5947 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5948 int declare_error = FALSE;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5949
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5950 if (get_var_dest(lhs->lhs_name, &lhs->lhs_dest, cmdidx,
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5951 &lhs->lhs_opt_flags, &lhs->lhs_vimvaridx,
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5952 &lhs->lhs_type, cctx) == FAIL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5953 return FAIL;
24293
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24283
diff changeset
5954 if (lhs->lhs_dest != dest_local
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24283
diff changeset
5955 && cmdidx != CMD_const && cmdidx != CMD_final)
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5956 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5957 // Specific kind of variable recognized.
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5958 declare_error = is_decl;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5959 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5960 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5961 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5962 int idx;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5963
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5964 // No specific kind of variable recognized, just a name.
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5965 for (idx = 0; reserved[idx] != NULL; ++idx)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5966 if (STRCMP(reserved[idx], lhs->lhs_name) == 0)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5967 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5968 semsg(_(e_cannot_use_reserved_name), lhs->lhs_name);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5969 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5970 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5971
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5972
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5973 if (lookup_local(var_start, lhs->lhs_varlen,
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5974 &lhs->lhs_local_lvar, cctx) == OK)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5975 lhs->lhs_lvar = &lhs->lhs_local_lvar;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5976 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5977 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5978 CLEAR_FIELD(lhs->lhs_arg_lvar);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5979 if (arg_exists(var_start, lhs->lhs_varlen,
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5980 &lhs->lhs_arg_lvar.lv_idx, &lhs->lhs_arg_lvar.lv_type,
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5981 &lhs->lhs_arg_lvar.lv_from_outer, cctx) == OK)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5982 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5983 if (is_decl)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5984 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5985 semsg(_(e_str_is_used_as_argument), lhs->lhs_name);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5986 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5987 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5988 lhs->lhs_lvar = &lhs->lhs_arg_lvar;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5989 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5990 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5991 if (lhs->lhs_lvar != NULL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5992 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5993 if (is_decl)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5994 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5995 semsg(_(e_variable_already_declared), lhs->lhs_name);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5996 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5997 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5998 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5999 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6000 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6001 int script_namespace = lhs->lhs_varlen > 1
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6002 && STRNCMP(var_start, "s:", 2) == 0;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6003 int script_var = (script_namespace
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6004 ? script_var_exists(var_start + 2, lhs->lhs_varlen - 2,
24388
72f3e40f046c patch 8.2.2734: Vim9: cannot use legacy script-local var from :def function
Bram Moolenaar <Bram@vim.org>
parents: 24379
diff changeset
6005 cctx)
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6006 : script_var_exists(var_start, lhs->lhs_varlen,
24388
72f3e40f046c patch 8.2.2734: Vim9: cannot use legacy script-local var from :def function
Bram Moolenaar <Bram@vim.org>
parents: 24379
diff changeset
6007 cctx)) == OK;
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6008 imported_T *import =
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6009 find_imported(var_start, lhs->lhs_varlen, cctx);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6010
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6011 if (script_namespace || script_var || import != NULL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6012 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6013 char_u *rawname = lhs->lhs_name
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6014 + (lhs->lhs_name[1] == ':' ? 2 : 0);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6015
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6016 if (is_decl)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6017 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6018 if (script_namespace)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6019 semsg(_(e_cannot_declare_script_variable_in_function),
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6020 lhs->lhs_name);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6021 else
24033
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
6022 semsg(_(e_variable_already_declared_in_script_str),
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6023 lhs->lhs_name);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6024 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6025 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6026 else if (cctx->ctx_ufunc->uf_script_ctx_version
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6027 == SCRIPT_VERSION_VIM9
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6028 && script_namespace
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6029 && !script_var && import == NULL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6030 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6031 semsg(_(e_unknown_variable_str), lhs->lhs_name);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6032 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6033 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6034
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6035 lhs->lhs_dest = dest_script;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6036
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6037 // existing script-local variables should have a type
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6038 lhs->lhs_scriptvar_sid = current_sctx.sc_sid;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6039 if (import != NULL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6040 lhs->lhs_scriptvar_sid = import->imp_sid;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6041 if (SCRIPT_ID_VALID(lhs->lhs_scriptvar_sid))
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6042 {
23578
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
6043 // Check writable only when no index follows.
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6044 lhs->lhs_scriptvar_idx = get_script_item_idx(
23578
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
6045 lhs->lhs_scriptvar_sid, rawname,
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
6046 lhs->lhs_has_index ? ASSIGN_FINAL : ASSIGN_CONST,
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
6047 cctx);
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6048 if (lhs->lhs_scriptvar_idx >= 0)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6049 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6050 scriptitem_T *si = SCRIPT_ITEM(
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6051 lhs->lhs_scriptvar_sid);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6052 svar_T *sv =
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6053 ((svar_T *)si->sn_var_vals.ga_data)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6054 + lhs->lhs_scriptvar_idx;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6055 lhs->lhs_type = sv->sv_type;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6056 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6057 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6058 }
24033
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
6059 else if (check_defined(var_start, lhs->lhs_varlen, cctx, FALSE)
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6060 == FAIL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6061 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6062 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6063 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6064
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6065 if (declare_error)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6066 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6067 vim9_declare_error(lhs->lhs_name);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6068 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6069 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6070 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6071
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6072 // handle "a:name" as a name, not index "name" on "a"
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6073 if (lhs->lhs_varlen > 1 || var_start[lhs->lhs_varlen] != ':')
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6074 var_end = lhs->lhs_dest_end;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6075
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6076 if (lhs->lhs_dest != dest_option)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6077 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6078 if (is_decl && *var_end == ':')
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6079 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6080 char_u *p;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6081
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6082 // parse optional type: "let var: type = expr"
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6083 if (!VIM_ISWHITE(var_end[1]))
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6084 {
23877
85cf06ddb2a8 patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents: 23837
diff changeset
6085 semsg(_(e_white_space_required_after_str_str), ":", var_end);
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6086 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6087 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6088 p = skipwhite(var_end + 1);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6089 lhs->lhs_type = parse_type(&p, cctx->ctx_type_list, TRUE);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6090 if (lhs->lhs_type == NULL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6091 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6092 lhs->lhs_has_type = TRUE;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6093 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6094 else if (lhs->lhs_lvar != NULL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6095 lhs->lhs_type = lhs->lhs_lvar->lv_type;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6096 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6097
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6098 if (oplen == 3 && !heredoc
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6099 && lhs->lhs_dest != dest_global
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6100 && !lhs->lhs_has_index
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6101 && lhs->lhs_type->tt_type != VAR_STRING
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6102 && lhs->lhs_type->tt_type != VAR_ANY)
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6103 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6104 emsg(_(e_can_only_concatenate_to_string));
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6105 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6106 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6107
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6108 if (lhs->lhs_lvar == NULL && lhs->lhs_dest == dest_local
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6109 && cctx->ctx_skip != SKIP_YES)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6110 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6111 if (oplen > 1 && !heredoc)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6112 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6113 // +=, /=, etc. require an existing variable
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6114 semsg(_(e_cannot_use_operator_on_new_variable), lhs->lhs_name);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6115 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6116 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6117 if (!is_decl)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6118 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6119 semsg(_(e_unknown_variable_str), lhs->lhs_name);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6120 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6121 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6122
24154
6e8f49a4a193 patch 8.2.2618: Vim9: cannot use a normal list name to store function refs
Bram Moolenaar <Bram@vim.org>
parents: 24152
diff changeset
6123 // Check the name is valid for a funcref.
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6124 if ((lhs->lhs_type->tt_type == VAR_FUNC
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6125 || lhs->lhs_type->tt_type == VAR_PARTIAL)
24154
6e8f49a4a193 patch 8.2.2618: Vim9: cannot use a normal list name to store function refs
Bram Moolenaar <Bram@vim.org>
parents: 24152
diff changeset
6126 && var_wrong_func_name(lhs->lhs_name, TRUE))
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6127 return FAIL;
24154
6e8f49a4a193 patch 8.2.2618: Vim9: cannot use a normal list name to store function refs
Bram Moolenaar <Bram@vim.org>
parents: 24152
diff changeset
6128
6e8f49a4a193 patch 8.2.2618: Vim9: cannot use a normal list name to store function refs
Bram Moolenaar <Bram@vim.org>
parents: 24152
diff changeset
6129 // New local variable.
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6130 lhs->lhs_lvar = reserve_local(cctx, var_start, lhs->lhs_varlen,
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6131 cmdidx == CMD_final || cmdidx == CMD_const, lhs->lhs_type);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6132 if (lhs->lhs_lvar == NULL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6133 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6134 lhs->lhs_new_local = TRUE;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6135 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6136
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6137 lhs->lhs_member_type = lhs->lhs_type;
23578
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
6138 if (lhs->lhs_has_index)
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6139 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6140 // Something follows after the variable: "var[idx]" or "var.key".
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6141 // TODO: should we also handle "->func()" here?
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6142 if (is_decl)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6143 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6144 emsg(_(e_cannot_use_index_when_declaring_variable));
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6145 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6146 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6147
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6148 if (var_start[lhs->lhs_varlen] == '['
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6149 || var_start[lhs->lhs_varlen] == '.')
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6150 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6151 char_u *after = var_start + lhs->lhs_varlen;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6152 char_u *p;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6153
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6154 // Only the last index is used below, if there are others
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6155 // before it generate code for the expression. Thus for
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6156 // "ll[1][2]" the expression is "ll[1]" and "[2]" is the index.
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6157 for (;;)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6158 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6159 p = skip_index(after);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6160 if (*p != '[' && *p != '.')
24512
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
6161 {
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
6162 lhs->lhs_varlen_total = p - var_start;
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6163 break;
24512
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
6164 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6165 after = p;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6166 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6167 if (after > var_start + lhs->lhs_varlen)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6168 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6169 lhs->lhs_varlen = after - var_start;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6170 lhs->lhs_dest = dest_expr;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6171 // We don't know the type before evaluating the expression,
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6172 // use "any" until then.
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6173 lhs->lhs_type = &t_any;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6174 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6175
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6176 if (lhs->lhs_type->tt_member == NULL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6177 lhs->lhs_member_type = &t_any;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6178 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6179 lhs->lhs_member_type = lhs->lhs_type->tt_member;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6180 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6181 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6182 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6183 semsg("Not supported yet: %s", var_start);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6184 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6185 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6186 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6187 return OK;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6188 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6189
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6190 /*
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6191 * Figure out the LHS and check a few errors.
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6192 */
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6193 static int
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6194 compile_assign_lhs(
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6195 char_u *var_start,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6196 lhs_T *lhs,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6197 int cmdidx,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6198 int is_decl,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6199 int heredoc,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6200 int oplen,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6201 cctx_T *cctx)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6202 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6203 if (compile_lhs(var_start, lhs, cmdidx, heredoc, oplen, cctx) == FAIL)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6204 return FAIL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6205
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6206 if (!lhs->lhs_has_index && lhs->lhs_lvar == &lhs->lhs_arg_lvar)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6207 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6208 semsg(_(e_cannot_assign_to_argument), lhs->lhs_name);
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6209 return FAIL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6210 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6211 if (!is_decl && lhs->lhs_lvar != NULL
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6212 && lhs->lhs_lvar->lv_const && !lhs->lhs_has_index)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6213 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6214 semsg(_(e_cannot_assign_to_constant), lhs->lhs_name);
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6215 return FAIL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6216 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6217 return OK;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6218 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6219
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6220 /*
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6221 * For an assignment with an index, compile the "idx" in "var[idx]" or "key" in
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6222 * "var.key".
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6223 */
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6224 static int
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6225 compile_assign_index(
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6226 char_u *var_start,
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6227 lhs_T *lhs,
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6228 int *range,
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6229 cctx_T *cctx)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6230 {
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6231 size_t varlen = lhs->lhs_varlen;
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6232 char_u *p;
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6233 int r = OK;
24434
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6234 int need_white_before = TRUE;
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6235 int empty_second;
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6236
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6237 p = var_start + varlen;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6238 if (*p == '[')
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6239 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6240 p = skipwhite(p + 1);
24434
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6241 if (*p == ':')
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6242 {
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6243 // empty first index, push zero
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6244 r = generate_PUSHNR(cctx, 0);
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6245 need_white_before = FALSE;
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6246 }
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6247 else
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6248 r = compile_expr0(&p, cctx);
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6249
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6250 if (r == OK && *skipwhite(p) == ':')
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6251 {
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6252 // unlet var[idx : idx]
24434
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6253 // blob[idx : idx] = value
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6254 *range = TRUE;
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6255 p = skipwhite(p);
24434
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6256 empty_second = *skipwhite(p + 1) == ']';
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6257 if ((need_white_before && !IS_WHITE_OR_NUL(p[-1]))
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6258 || (!empty_second && !IS_WHITE_OR_NUL(p[1])))
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6259 {
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6260 semsg(_(e_white_space_required_before_and_after_str_at_str),
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6261 ":", p);
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6262 return FAIL;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6263 }
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6264 p = skipwhite(p + 1);
24434
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6265 if (*p == ']')
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6266 // empty second index, push "none"
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6267 r = generate_PUSHSPEC(cctx, VVAL_NONE);
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6268 else
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6269 r = compile_expr0(&p, cctx);
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6270 }
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6271
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6272 if (r == OK && *skipwhite(p) != ']')
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6273 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6274 // this should not happen
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6275 emsg(_(e_missbrac));
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6276 r = FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6277 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6278 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6279 else // if (*p == '.')
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6280 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6281 char_u *key_end = to_name_end(p + 1, TRUE);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6282 char_u *key = vim_strnsave(p + 1, key_end - p - 1);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6283
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6284 r = generate_PUSHS(cctx, key);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6285 }
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6286 return r;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6287 }
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6288
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6289 /*
24363
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6290 * For a LHS with an index, load the variable to be indexed.
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6291 */
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6292 static int
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6293 compile_load_lhs(
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6294 lhs_T *lhs,
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6295 char_u *var_start,
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6296 type_T *rhs_type,
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6297 cctx_T *cctx)
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6298 {
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6299 if (lhs->lhs_dest == dest_expr)
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6300 {
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6301 size_t varlen = lhs->lhs_varlen;
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6302 int c = var_start[varlen];
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6303 char_u *p = var_start;
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6304 garray_T *stack = &cctx->ctx_type_stack;
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6305
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6306 // Evaluate "ll[expr]" of "ll[expr][idx]"
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6307 var_start[varlen] = NUL;
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6308 if (compile_expr0(&p, cctx) == OK && p != var_start + varlen)
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6309 {
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6310 // this should not happen
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6311 emsg(_(e_missbrac));
24379
8d5e4b50c2e1 patch 8.2.2730: Coverity complains about not restoring character
Bram Moolenaar <Bram@vim.org>
parents: 24377
diff changeset
6312 var_start[varlen] = c;
24363
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6313 return FAIL;
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6314 }
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6315 var_start[varlen] = c;
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6316
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6317 lhs->lhs_type = stack->ga_len == 0 ? &t_void
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6318 : ((type_T **)stack->ga_data)[stack->ga_len - 1];
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6319 // now we can properly check the type
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6320 if (rhs_type != NULL && lhs->lhs_type->tt_member != NULL
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6321 && rhs_type != &t_void
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6322 && need_type(rhs_type, lhs->lhs_type->tt_member, -2, 0, cctx,
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6323 FALSE, FALSE) == FAIL)
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6324 return FAIL;
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6325 }
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6326 else
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6327 generate_loadvar(cctx, lhs->lhs_dest, lhs->lhs_name,
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6328 lhs->lhs_lvar, lhs->lhs_type);
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6329 return OK;
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6330 }
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6331
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6332 /*
24516
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6333 * Produce code for loading "lhs" and also take care of an index.
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6334 * Return OK/FAIL.
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6335 */
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6336 static int
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6337 compile_load_lhs_with_index(lhs_T *lhs, char_u *var_start, cctx_T *cctx)
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6338 {
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6339 compile_load_lhs(lhs, var_start, NULL, cctx);
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6340
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6341 if (lhs->lhs_has_index)
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6342 {
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6343 int range = FALSE;
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6344
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6345 // Get member from list or dict. First compile the
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6346 // index value.
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6347 if (compile_assign_index(var_start, lhs, &range, cctx) == FAIL)
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6348 return FAIL;
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6349 if (range)
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6350 {
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6351 semsg(_(e_cannot_use_range_with_assignment_operator_str),
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6352 var_start);
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6353 return FAIL;
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6354 }
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6355
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6356 // Get the member.
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6357 if (compile_member(FALSE, cctx) == FAIL)
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6358 return FAIL;
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6359 }
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6360 return OK;
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6361 }
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6362
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6363 /*
24357
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6364 * Assignment to a list or dict member, or ":unlet" for the item, using the
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6365 * information in "lhs".
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6366 * Returns OK or FAIL.
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6367 */
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6368 static int
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6369 compile_assign_unlet(
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6370 char_u *var_start,
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6371 lhs_T *lhs,
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6372 int is_assign,
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6373 type_T *rhs_type,
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6374 cctx_T *cctx)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6375 {
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6376 vartype_T dest_type;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6377 garray_T *stack = &cctx->ctx_type_stack;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6378 int range = FALSE;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6379
24434
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6380 if (compile_assign_index(var_start, lhs, &range, cctx) == FAIL)
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6381 return FAIL;
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6382 if (is_assign && range && lhs->lhs_type != &t_blob
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6383 && lhs->lhs_type != &t_any)
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6384 {
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6385 semsg(_(e_cannot_use_range_with_assignment_str), var_start);
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6386 return FAIL;
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6387 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6388
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6389 if (lhs->lhs_type == &t_any)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6390 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6391 // Index on variable of unknown type: check at runtime.
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6392 dest_type = VAR_ANY;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6393 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6394 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6395 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6396 dest_type = lhs->lhs_type->tt_type;
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6397 if (dest_type == VAR_DICT && range)
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6398 {
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6399 emsg(e_cannot_use_range_with_dictionary);
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6400 return FAIL;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6401 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6402 if (dest_type == VAR_DICT && may_generate_2STRING(-1, cctx) == FAIL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6403 return FAIL;
24475
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6404 if (dest_type == VAR_LIST || dest_type == VAR_BLOB)
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6405 {
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6406 type_T *type;
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6407
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6408 if (range)
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6409 {
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6410 type = ((type_T **)stack->ga_data)[stack->ga_len - 2];
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6411 if (need_type(type, &t_number,
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6412 -1, 0, cctx, FALSE, FALSE) == FAIL)
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6413 return FAIL;
24475
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6414 }
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6415 type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6416 if ((dest_type != VAR_BLOB || type != &t_special)
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6417 && need_type(type, &t_number,
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6418 -1, 0, cctx, FALSE, FALSE) == FAIL)
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6419 return FAIL;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6420 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6421 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6422
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6423 // Load the dict or list. On the stack we then have:
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6424 // - value (for assignment, not for :unlet)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6425 // - index
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6426 // - for [a : b] second index
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6427 // - variable
24363
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6428 if (compile_load_lhs(lhs, var_start, rhs_type, cctx) == FAIL)
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6429 return FAIL;
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6430
24434
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6431 if (dest_type == VAR_LIST || dest_type == VAR_DICT
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6432 || dest_type == VAR_BLOB || dest_type == VAR_ANY)
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6433 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6434 if (is_assign)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6435 {
24434
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6436 if (range)
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6437 {
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6438 if (generate_instr_drop(cctx, ISN_STORERANGE, 4) == NULL)
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6439 return FAIL;
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6440 }
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6441 else
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6442 {
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6443 isn_T *isn = generate_instr_drop(cctx, ISN_STOREINDEX, 3);
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6444
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6445 if (isn == NULL)
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6446 return FAIL;
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6447 isn->isn_arg.vartype = dest_type;
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6448 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6449 }
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6450 else if (range)
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6451 {
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6452 if (generate_instr_drop(cctx, ISN_UNLETRANGE, 3) == NULL)
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6453 return FAIL;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6454 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6455 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6456 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6457 if (generate_instr_drop(cctx, ISN_UNLETINDEX, 2) == NULL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6458 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6459 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6460 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6461 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6462 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6463 emsg(_(e_indexable_type_required));
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6464 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6465 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6466
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6467 return OK;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6468 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6469
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6470 /*
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6471 * Compile declaration and assignment:
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6472 * "let name"
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6473 * "var name = expr"
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6474 * "final name = expr"
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6475 * "const name = expr"
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6476 * "name = expr"
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6477 * "arg" points to "name".
24533
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6478 * "++arg" and "--arg"
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6479 * 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
6480 * 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
6481 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6482 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6483 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
6484 {
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6485 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
6486 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
6487 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
6488 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
6489 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
6490 int var_idx;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6491 int semicolon = 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6492 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
6493 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
6494 char_u *op;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6495 int oplen = 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6496 int heredoc = FALSE;
24533
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6497 int incdec = FALSE;
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6498 type_T *rhs_type = &t_any;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6499 char_u *sp;
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6500 int is_decl = is_decl_command(cmdidx);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6501 lhs_T lhs;
24329
cd9f77409393 patch 8.2.2705: Vim9: misleading reported line number for wrong type
Bram Moolenaar <Bram@vim.org>
parents: 24295
diff changeset
6502 long start_lnum = SOURCING_LNUM;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6503
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6504 // 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
6505 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
6506 if (p == NULL)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6507 return *arg == '[' ? arg : NULL;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6508
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6509 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
6510 {
21421
0f0fee4122d3 patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents: 21411
diff changeset
6511 // 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
6512 // members?
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
6513 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
6514 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6515 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6516 lhs.lhs_name = NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6517
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6518 sp = p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6519 p = skipwhite(p);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6520 op = p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6521 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
6522
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6523 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
6524 // 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
6525 return arg;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6526
23052
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
6527 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
6528 {
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
6529 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
6530 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
6531 }
24533
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6532 if (eap->cmdidx == CMD_increment || eap->cmdidx == CMD_decrement)
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6533 {
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6534 op = (char_u *)(eap->cmdidx == CMD_increment ? "+=" : "-=");
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6535 oplen = 2;
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6536 incdec = TRUE;
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6537 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6538
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6539 if (heredoc)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6540 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6541 list_T *l;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6542 listitem_T *li;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6543
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6544 // [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
6545 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
6546 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
6547 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
6548 if (l == NULL)
66d1131a7eff patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
6549 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6550
22343
9f5a84baa464 patch 8.2.1720: Vim9: memory leak with heredoc that isn't executed
Bram Moolenaar <Bram@vim.org>
parents: 22341
diff changeset
6551 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
6552 {
22343
9f5a84baa464 patch 8.2.1720: Vim9: memory leak with heredoc that isn't executed
Bram Moolenaar <Bram@vim.org>
parents: 22341
diff changeset
6553 // 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
6554 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
6555 {
9f5a84baa464 patch 8.2.1720: Vim9: memory leak with heredoc that isn't executed
Bram Moolenaar <Bram@vim.org>
parents: 22341
diff changeset
6556 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
6557 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
6558 }
9f5a84baa464 patch 8.2.1720: Vim9: memory leak with heredoc that isn't executed
Bram Moolenaar <Bram@vim.org>
parents: 22341
diff changeset
6559 generate_NEWLIST(cctx, l->lv_len);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6560 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6561 list_free(l);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6562 p += STRLEN(p);
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6563 end = p;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6564 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6565 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
6566 {
23052
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
6567 char_u *wp;
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
6568
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6569 // 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
6570 // 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
6571 // 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
6572
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
6573 wp = op + oplen;
23122
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23114
diff changeset
6574 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
6575 return FAIL;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6576 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
6577 return NULL;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6578 end = p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6579
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
6580 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
6581 {
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6582 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
6583
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19934
diff changeset
6584 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
6585 : ((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
6586 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
6587 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
6588 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
6589 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6590 }
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
6591 if (need_type(stacktype, &t_list_any, -1, 0, cctx,
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
6592 FALSE, FALSE) == FAIL)
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6593 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
6594 // 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
6595 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
6596 semicolon);
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6597 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
6598 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
6599 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6600 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6601
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6602 /*
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6603 * 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
6604 * 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
6605 */
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6606 if (var_count > 0)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6607 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
6608 else
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6609 var_start = arg;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6610 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
6611 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6612 int instr_count = -1;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6613
24426
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6614 if (var_start[0] == '_' && !eval_isnamec(var_start[1]))
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6615 {
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6616 // Ignore underscore in "[a, _, b] = list".
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6617 if (var_count > 0)
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6618 {
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6619 var_start = skipwhite(var_start + 2);
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6620 continue;
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6621 }
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6622 emsg(_(e_cannot_use_underscore_here));
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6623 goto theend;
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6624 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6625 vim_free(lhs.lhs_name);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6626
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6627 /*
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6628 * Figure out the LHS type and other properties.
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6629 */
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6630 if (compile_assign_lhs(var_start, &lhs, cmdidx,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6631 is_decl, heredoc, oplen, cctx) == FAIL)
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6632 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6633 if (!heredoc)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6634 {
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
6635 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
6636 {
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6637 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
6638 {
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6639 // 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
6640 p = skipwhite(op + oplen);
24510
b5786b4de9d1 patch 8.2.2795: Coverity warns for not using return value
Bram Moolenaar <Bram@vim.org>
parents: 24502
diff changeset
6641 (void)compile_expr0(&p, cctx);
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6642 }
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6643 }
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6644 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
6645 {
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
6646 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
6647 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
6648
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6649 // 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
6650 if (var_count == 0)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6651 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6652 int r;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6653
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6654 // 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
6655 if (*op != '=')
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6656 {
24516
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6657 if (compile_load_lhs_with_index(&lhs, var_start,
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6658 cctx) == FAIL)
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
6659 goto theend;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6660 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6661
24533
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6662 // Compile the expression.
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6663 instr_count = instr->ga_len;
24533
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6664 if (incdec)
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6665 {
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6666 r = generate_PUSHNR(cctx, 1);
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6667 }
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6668 else
23082
2120e4b40e12 patch 8.2.2087: Vim9: memory leak when statement is truncated
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
6669 {
24533
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6670 // Temporarily hide the new local variable here, it is
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6671 // not available to this expression.
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6672 if (lhs.lhs_new_local)
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6673 --cctx->ctx_locals.ga_len;
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6674 wp = op + oplen;
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6675 if (may_get_next_line_error(wp, &p, cctx) == FAIL)
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6676 {
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6677 if (lhs.lhs_new_local)
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6678 ++cctx->ctx_locals.ga_len;
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6679 goto theend;
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6680 }
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6681 r = compile_expr0_ext(&p, cctx, &is_const);
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6682 if (lhs.lhs_new_local)
23082
2120e4b40e12 patch 8.2.2087: Vim9: memory leak when statement is truncated
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
6683 ++cctx->ctx_locals.ga_len;
24533
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6684 if (r == FAIL)
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6685 goto theend;
23082
2120e4b40e12 patch 8.2.2087: Vim9: memory leak when statement is truncated
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
6686 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6687 }
20871
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
6688 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
6689 {
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
6690 // 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
6691 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
6692 goto theend;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
6693 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6694 else
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6695 {
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6696 // 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
6697 // list.
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6698 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
6699 goto theend;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6700 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6701
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6702 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
6703 : ((type_T **)stack->ga_data)[stack->ga_len - 1];
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6704 if (lhs.lhs_lvar != NULL && (is_decl || !lhs.lhs_has_type))
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6705 {
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6706 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
6707 || rhs_type->tt_type == VAR_PARTIAL)
24154
6e8f49a4a193 patch 8.2.2618: Vim9: cannot use a normal list name to store function refs
Bram Moolenaar <Bram@vim.org>
parents: 24152
diff changeset
6708 && !lhs.lhs_has_index
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6709 && var_wrong_func_name(lhs.lhs_name, TRUE))
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
6710 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
6711
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6712 if (lhs.lhs_new_local && !lhs.lhs_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
6713 {
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6714 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
6715 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
6716 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
6717 goto theend;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6718 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6719 else
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6720 {
22363
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22343
diff changeset
6721 // 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
6722 // 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
6723 if (rhs_type == &t_list_empty)
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6724 lhs.lhs_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
6725 else if (rhs_type == &t_dict_empty)
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6726 lhs.lhs_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
6727 else if (rhs_type == &t_unknown)
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6728 lhs.lhs_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
6729 else
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6730 lhs.lhs_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
6731 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6732 }
21881
675bf9475fff patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
6733 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
6734 {
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6735 type_T *use_type = lhs.lhs_lvar->lv_type;
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6736
24329
cd9f77409393 patch 8.2.2705: Vim9: misleading reported line number for wrong type
Bram Moolenaar <Bram@vim.org>
parents: 24295
diff changeset
6737 // Without operator check type here, otherwise below.
cd9f77409393 patch 8.2.2705: Vim9: misleading reported line number for wrong type
Bram Moolenaar <Bram@vim.org>
parents: 24295
diff changeset
6738 // Use the line number of the assignment.
cd9f77409393 patch 8.2.2705: Vim9: misleading reported line number for wrong type
Bram Moolenaar <Bram@vim.org>
parents: 24295
diff changeset
6739 SOURCING_LNUM = start_lnum;
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6740 if (lhs.lhs_has_index)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6741 use_type = lhs.lhs_member_type;
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
6742 if (need_type(rhs_type, use_type, -1, 0, cctx,
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
6743 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
6744 goto theend;
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6745 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6746 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6747 else if (*p != '=' && need_type(rhs_type, lhs.lhs_member_type,
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
6748 -1, 0, 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
6749 goto theend;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6750 }
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6751 else if (cmdidx == CMD_final)
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6752 {
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6753 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
6754 goto theend;
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6755 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6756 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
6757 {
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
6758 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
6759 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6760 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6761 else if (!lhs.lhs_has_type || lhs.lhs_dest == dest_option)
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6762 {
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
6763 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
6764 goto theend;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6765 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6766 else
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6767 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6768 // variables are always initialized
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6769 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
6770 goto theend;
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6771 switch (lhs.lhs_member_type->tt_type)
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6772 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6773 case VAR_BOOL:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6774 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
6775 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6776 case VAR_FLOAT:
19336
1cd6eab65ce0 patch 8.2.0226: compiling for loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
6777 #ifdef FEAT_FLOAT
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6778 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
6779 #endif
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6780 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6781 case VAR_STRING:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6782 generate_PUSHS(cctx, NULL);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6783 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6784 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
6785 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
6786 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6787 case VAR_FUNC:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6788 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
6789 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6790 case VAR_LIST:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6791 generate_NEWLIST(cctx, 0);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6792 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6793 case VAR_DICT:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6794 generate_NEWDICT(cctx, 0);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6795 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6796 case VAR_JOB:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6797 generate_PUSHJOB(cctx, NULL);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6798 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6799 case VAR_CHANNEL:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6800 generate_PUSHCHANNEL(cctx, NULL);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6801 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6802 case VAR_NUMBER:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6803 case VAR_UNKNOWN:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6804 case VAR_ANY:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6805 case VAR_PARTIAL:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6806 case VAR_VOID:
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
6807 case VAR_INSTR:
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6808 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
6809 generate_PUSHNR(cctx, 0);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6810 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6811 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6812 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6813 if (var_count == 0)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6814 end = p;
19336
1cd6eab65ce0 patch 8.2.0226: compiling for loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
6815 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6816
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6817 // 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
6818 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
6819 break;
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6820
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6821 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
6822 {
21881
675bf9475fff patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
6823 type_T *expected;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6824 type_T *stacktype;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6825
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6826 if (*op == '.')
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6827 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
6828 else
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6829 expected = lhs.lhs_member_type;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6830 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
6831 if (
675bf9475fff patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
6832 #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
6833 // 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
6834 !(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
6835 #endif
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
6836 need_type(stacktype, expected, -1, 0, cctx,
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
6837 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
6838 goto theend;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6839
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6840 if (*op == '.')
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
6841 {
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
6842 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
6843 goto theend;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
6844 }
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
6845 else if (*op == '+')
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
6846 {
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
6847 if (generate_add_instr(cctx,
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6848 operator_type(lhs.lhs_member_type, stacktype),
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6849 lhs.lhs_member_type, stacktype) == FAIL)
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
6850 goto theend;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
6851 }
21881
675bf9475fff patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
6852 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
6853 goto theend;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6854 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6855
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6856 if (lhs.lhs_has_index)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6857 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6858 // Use the info in "lhs" to store the value at the index in the
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6859 // list or dict.
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6860 if (compile_assign_unlet(var_start, &lhs, TRUE, rhs_type, cctx)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6861 == FAIL)
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6862 goto theend;
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6863 }
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6864 else
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6865 {
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6866 if (is_decl && cmdidx == CMD_const && (lhs.lhs_dest == dest_script
24293
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24283
diff changeset
6867 || lhs.lhs_dest == dest_global
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6868 || lhs.lhs_dest == dest_local))
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6869 // ":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
6870 generate_LOCKCONST(cctx);
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
6871
23458
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
6872 if (is_decl
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6873 && (lhs.lhs_type->tt_type == VAR_DICT
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6874 || lhs.lhs_type->tt_type == VAR_LIST)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6875 && lhs.lhs_type->tt_member != NULL
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6876 && lhs.lhs_type->tt_member != &t_any
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6877 && lhs.lhs_type->tt_member != &t_unknown)
23458
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
6878 // 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
6879 // also in legacy script.
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6880 generate_SETTYPE(cctx, lhs.lhs_type);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6881
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6882 if (generate_store_lhs(cctx, &lhs, instr_count) == FAIL)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6883 goto theend;
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6884 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6885
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6886 if (var_idx + 1 < var_count)
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6887 var_start = skipwhite(lhs.lhs_dest_end + 1);
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6888 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6889
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6890 // 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
6891 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
6892 {
23195
75f35ae990ac patch 8.2.2143: Vim9: dead code in compiling :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23187
diff changeset
6893 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
6894 goto theend;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
6895 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6896
21391
8b882afa8ed2 patch 8.2.1246: Vim9: comment after assignment doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21387
diff changeset
6897 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
6898
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6899 theend:
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6900 vim_free(lhs.lhs_name);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6901 return ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6902 }
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 /*
23537
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6905 * Check for an assignment at "eap->cmd", compile it if found.
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6906 * Return NOTDONE if there is none, FAIL for failure, OK if done.
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6907 */
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6908 static int
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6909 may_compile_assignment(exarg_T *eap, char_u **line, cctx_T *cctx)
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6910 {
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6911 char_u *pskip;
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6912 char_u *p;
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6913
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6914 // Assuming the command starts with a variable or function name,
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6915 // find what follows.
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6916 // Skip over "var.member", "var[idx]" and the like.
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6917 // Also "&opt = val", "$ENV = val" and "@r = val".
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6918 pskip = (*eap->cmd == '&' || *eap->cmd == '$' || *eap->cmd == '@')
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6919 ? eap->cmd + 1 : eap->cmd;
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6920 p = to_name_end(pskip, TRUE);
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6921 if (p > eap->cmd && *p != NUL)
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6922 {
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6923 char_u *var_end;
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6924 int oplen;
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6925 int heredoc;
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6926
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6927 if (eap->cmd[0] == '@')
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6928 var_end = eap->cmd + 2;
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6929 else
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6930 var_end = find_name_end(pskip, NULL, NULL,
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6931 FNE_CHECK_START | FNE_INCL_BR);
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6932 oplen = assignment_len(skipwhite(var_end), &heredoc);
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6933 if (oplen > 0)
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6934 {
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6935 size_t len = p - eap->cmd;
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6936
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6937 // Recognize an assignment if we recognize the variable
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6938 // name:
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6939 // "g:var = expr"
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6940 // "local = expr" where "local" is a local var.
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6941 // "script = expr" where "script" is a script-local var.
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6942 // "import = expr" where "import" is an imported var
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6943 // "&opt = expr"
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6944 // "$ENV = expr"
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6945 // "@r = expr"
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6946 if (*eap->cmd == '&'
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6947 || *eap->cmd == '$'
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6948 || *eap->cmd == '@'
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6949 || ((len) > 2 && eap->cmd[1] == ':')
23966
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
6950 || variable_exists(eap->cmd, len, cctx))
23537
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6951 {
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6952 *line = compile_assignment(eap->cmd, eap, CMD_SIZE, cctx);
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6953 if (*line == NULL || *line == eap->cmd)
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6954 return FAIL;
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6955 return OK;
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6956 }
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6957 }
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6958 }
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6959
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6960 if (*eap->cmd == '[')
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6961 {
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6962 // [var, var] = expr
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6963 *line = compile_assignment(eap->cmd, eap, CMD_SIZE, cctx);
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6964 if (*line == NULL)
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6965 return FAIL;
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6966 if (*line != eap->cmd)
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6967 return OK;
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6968 }
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6969 return NOTDONE;
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6970 }
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6971
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6972 /*
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6973 * 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
6974 */
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6975 int
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6976 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
6977 {
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6978 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
6979 {
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
6980 // "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
6981 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
6982 return OK;
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
6983 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
6984 return FAIL;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6985 }
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6986 return OK;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6987 }
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6988
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6989 /*
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6990 * Callback passed to ex_unletlock().
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6991 */
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6992 static int
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6993 compile_unlet(
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6994 lval_T *lvp,
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6995 char_u *name_end,
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6996 exarg_T *eap,
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6997 int deep UNUSED,
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6998 void *coookie)
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6999 {
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7000 cctx_T *cctx = coookie;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7001 char_u *p = lvp->ll_name;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7002 int cc = *name_end;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7003 int ret = OK;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7004
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7005 if (cctx->ctx_skip == SKIP_YES)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7006 return OK;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7007
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7008 *name_end = NUL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7009 if (*p == '$')
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7010 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7011 // :unlet $ENV_VAR
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7012 ret = generate_UNLET(cctx, ISN_UNLETENV, p + 1, eap->forceit);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7013 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7014 else if (vim_strchr(p, '.') != NULL || vim_strchr(p, '[') != NULL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7015 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7016 lhs_T lhs;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7017
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7018 // This is similar to assigning: lookup the list/dict, compile the
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7019 // idx/key. Then instead of storing the value unlet the item.
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7020 // unlet {list}[idx]
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7021 // unlet {dict}[key] dict.key
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7022 //
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7023 // Figure out the LHS type and other properties.
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7024 //
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7025 ret = compile_lhs(p, &lhs, CMD_unlet, FALSE, 0, cctx);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7026
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7027 // : unlet an indexed item
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7028 if (!lhs.lhs_has_index)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7029 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7030 iemsg("called compile_lhs() without an index");
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7031 ret = FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7032 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7033 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7034 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7035 // Use the info in "lhs" to unlet the item at the index in the
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7036 // list or dict.
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7037 ret = compile_assign_unlet(p, &lhs, FALSE, &t_void, cctx);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7038 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7039
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7040 vim_free(lhs.lhs_name);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7041 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7042 else if (check_vim9_unlet(p) == FAIL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7043 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7044 ret = FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7045 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7046 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7047 {
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7048 // Normal name. Only supports g:, w:, t: and b: namespaces.
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7049 ret = generate_UNLET(cctx, ISN_UNLET, p, eap->forceit);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7050 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7051
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7052 *name_end = cc;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7053 return ret;
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7054 }
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7055
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7056 /*
24262
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7057 * Callback passed to ex_unletlock().
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7058 */
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7059 static int
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7060 compile_lock_unlock(
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7061 lval_T *lvp,
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7062 char_u *name_end,
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7063 exarg_T *eap,
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7064 int deep UNUSED,
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7065 void *coookie)
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7066 {
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7067 cctx_T *cctx = coookie;
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7068 int cc = *name_end;
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7069 char_u *p = lvp->ll_name;
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7070 int ret = OK;
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7071 size_t len;
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7072 char_u *buf;
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7073
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7074 if (cctx->ctx_skip == SKIP_YES)
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7075 return OK;
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7076
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7077 // Cannot use :lockvar and :unlockvar on local variables.
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7078 if (p[1] != ':')
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7079 {
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7080 char_u *end = skip_var_one(p, FALSE);
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7081
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7082 if (lookup_local(p, end - p, NULL, cctx) == OK)
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7083 {
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7084 emsg(_(e_cannot_lock_unlock_local_variable));
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7085 return FAIL;
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7086 }
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7087 }
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7088
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7089 // Checking is done at runtime.
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7090 *name_end = NUL;
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7091 len = name_end - p + 20;
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7092 buf = alloc(len);
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7093 if (buf == NULL)
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7094 ret = FAIL;
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7095 else
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7096 {
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7097 vim_snprintf((char *)buf, len, "%s %s",
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7098 eap->cmdidx == CMD_lockvar ? "lockvar" : "unlockvar",
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7099 p);
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7100 ret = generate_EXEC(cctx, buf);
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7101
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7102 vim_free(buf);
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7103 *name_end = cc;
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7104 }
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7105 return ret;
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7106 }
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7107
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7108 /*
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7109 * 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
7110 * "arg" points to "var".
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7111 */
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7112 static char_u *
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7113 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
7114 {
24262
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7115 ex_unletlock(eap, arg, 0, GLV_NO_AUTOLOAD | GLV_COMPILING,
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7116 eap->cmdidx == CMD_unlet ? compile_unlet : compile_lock_unlock,
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7117 cctx);
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7118 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
7119 }
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7120
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7121 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7122 * 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
7123 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7124 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7125 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
7126 {
21146
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
7127 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
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7131 * 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
7132 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7133 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7134 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
7135 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7136 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
7137 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
7138
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7139 if (endlabel == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7140 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7141 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
7142 *el = endlabel;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7143 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
7144
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7145 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
7146 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7147 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7148
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7149 static void
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
7150 compile_fill_jump_to_end(endlabel_T **el, int jump_where, 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
7151 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7152 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
7153
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7154 while (*el != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7155 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7156 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
7157 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7158
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7159 isn = ((isn_T *)instr->ga_data) + cur->el_end_label;
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
7160 isn->isn_arg.jump.jump_where = jump_where;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7161 *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
7162 vim_free(cur);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7163 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7164 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7165
19896
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7166 static void
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7167 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
7168 {
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7169 while (*el != NULL)
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7170 {
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7171 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
7172
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7173 *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
7174 vim_free(cur);
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7175 }
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7176 }
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7177
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7178 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7179 * 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
7180 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7181 static scope_T *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7182 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
7183 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7184 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
7185
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7186 if (scope == NULL)
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 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
7189 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
7190 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
7191 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
7192 return scope;
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
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7195 /*
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7196 * 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
7197 */
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7198 static void
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7199 drop_scope(cctx_T *cctx)
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7200 {
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7201 scope_T *scope = cctx->ctx_scope;
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7202
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7203 if (scope == NULL)
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7204 {
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7205 iemsg("calling drop_scope() without a scope");
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7206 return;
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7207 }
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7208 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
7209 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
7210 {
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7211 case IF_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7212 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
7213 case FOR_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7214 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
7215 case WHILE_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7216 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
7217 case TRY_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7218 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
7219 case NO_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7220 case BLOCK_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7221 break;
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7222 }
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7223 vim_free(scope);
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7224 }
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7225
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7226 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7227 * compile "if expr"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7228 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7229 * "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
7230 * 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
7231 * 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
7232 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7233 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7234 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7235 * "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
7236 * 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
7237 * 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
7238 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7239 * JUMP_ALWAYS end
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7240 * else:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7241 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7242 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7243 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7244 * "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
7245 * 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
7246 * 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
7247 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7248 * JUMP_ALWAYS end
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7249 * elseif:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7250 * 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
7251 * 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
7252 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7253 * JUMP_ALWAYS end
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7254 * else:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7255 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7256 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7257 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7258 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7259 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
7260 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7261 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
7262 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
7263 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
7264 scope_T *scope;
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7265 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
7266 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
7267
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
7268 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
7269 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
7270 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
7271 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
7272 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
7273 }
23882
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7274 if (!ends_excmd2(arg, skipwhite(p)))
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7275 {
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7276 semsg(_(e_trailing_arg), p);
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7277 return NULL;
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7278 }
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7279 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
7280 clear_ppconst(&ppconst);
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7281 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
7282 {
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7283 int error = FALSE;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7284 int v;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7285
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
7286 // 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
7287 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
7288 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
7289 if (error)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7290 return NULL;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7291 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
7292 }
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7293 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
7294 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
7295 // 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
7296 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
7297 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
7298 return NULL;
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7299 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
7300 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
7301 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7302
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7303 // CMDMOD_REV must come before the jump
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7304 generate_undo_cmdmods(cctx);
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7305
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7306 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
7307 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7308 return NULL;
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7309 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
7310 // "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
7311 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
7312
20933
e2fd5f05342f patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents: 20929
diff changeset
7313 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
7314 {
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7315 // "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
7316 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
7317 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
7318 }
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7319 else
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7320 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
7321
23723
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7322 #ifdef FEAT_PROFILE
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7323 if (cctx->ctx_profiling && cctx->ctx_skip == SKIP_YES
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7324 && skip_save != SKIP_YES)
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7325 {
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7326 // generated a profile start, need to generate a profile end, since it
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7327 // won't be done after returning
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7328 cctx->ctx_skip = SKIP_NOT;
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7329 generate_instr(cctx, ISN_PROF_END);
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7330 cctx->ctx_skip = SKIP_YES;
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7331 }
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7332 #endif
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7333
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7334 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7335 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7336
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7337 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7338 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
7339 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7340 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
7341 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
7342 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
7343 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7344 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
7345 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
7346 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
7347
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7348 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
7349 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7350 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
7351 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7352 }
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
7353 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
7354 if (!cctx->ctx_had_return)
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7355 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
7356
23723
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7357 if (cctx->ctx_skip == SKIP_NOT)
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7358 {
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7359 // previous block was executed, this one and following will not
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7360 cctx->ctx_skip = SKIP_YES;
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7361 scope->se_u.se_if.is_seen_skip_not = TRUE;
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7362 }
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7363 if (scope->se_u.se_if.is_seen_skip_not)
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7364 {
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7365 // A previous block was executed, skip over expression and bail out.
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7366 // Do not count the "elseif" for profiling and cmdmod
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7367 instr->ga_len = current_instr_idx(cctx);
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7368
23723
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7369 skip_expr_cctx(&p, cctx);
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7370 return p;
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7371 }
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7372
20933
e2fd5f05342f patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents: 20929
diff changeset
7373 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
7374 {
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7375 int moved_cmdmod = FALSE;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7376
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7377 // Move any CMDMOD instruction to after the jump
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7378 if (((isn_T *)instr->ga_data)[instr->ga_len - 1].isn_type == ISN_CMDMOD)
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7379 {
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7380 if (ga_grow(instr, 1) == FAIL)
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7381 return NULL;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7382 ((isn_T *)instr->ga_data)[instr->ga_len] =
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7383 ((isn_T *)instr->ga_data)[instr->ga_len - 1];
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7384 --instr->ga_len;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7385 moved_cmdmod = TRUE;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7386 }
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7387
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7388 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
7389 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
7390 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
7391 // 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
7392 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
7393 isn->isn_arg.jump.jump_where = instr->ga_len;
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7394 if (moved_cmdmod)
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7395 ++instr->ga_len;
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7396 }
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7397
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7398 // 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
7399 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
7400 if (cctx->ctx_skip == SKIP_YES)
23723
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7401 {
21959
67d4be2757b0 patch 8.2.1529: Vim9: :elseif may be compiled when not needed
Bram Moolenaar <Bram@vim.org>
parents: 21957
diff changeset
7402 cctx->ctx_skip = SKIP_UNKNOWN;
23723
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7403 #ifdef FEAT_PROFILE
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7404 if (cctx->ctx_profiling)
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7405 {
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7406 // the previous block was skipped, need to profile this line
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7407 generate_instr(cctx, ISN_PROF_START);
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7408 instr_count = instr->ga_len;
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7409 }
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7410 #endif
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7411 }
20334
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7412 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
7413 {
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7414 clear_ppconst(&ppconst);
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7415 return NULL;
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7416 }
21959
67d4be2757b0 patch 8.2.1529: Vim9: :elseif may be compiled when not needed
Bram Moolenaar <Bram@vim.org>
parents: 21957
diff changeset
7417 cctx->ctx_skip = save_skip;
23882
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7418 if (!ends_excmd2(arg, skipwhite(p)))
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7419 {
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7420 semsg(_(e_trailing_arg), p);
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7421 return NULL;
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7422 }
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7423 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
7424 clear_ppconst(&ppconst);
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7425 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
7426 {
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7427 int error = FALSE;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7428 int v;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7429
20334
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7430 // 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
7431 // 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
7432 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
7433 if (error)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7434 return NULL;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7435 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
7436 clear_ppconst(&ppconst);
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7437 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
7438 }
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7439 else
20334
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7440 {
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7441 // 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
7442 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
7443 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
7444 return NULL;
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7445 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
7446 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
7447
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7448 // CMDMOD_REV must come before the jump
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7449 generate_undo_cmdmods(cctx);
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7450
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7451 // "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
7452 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
7453 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
7454 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7455
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7456 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7457 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7458
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7459 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7460 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
7461 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7462 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
7463 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
7464 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7465 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
7466
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7467 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
7468 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7469 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
7470 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7471 }
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
7472 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
7473 if (!cctx->ctx_had_return)
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7474 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
7475 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
7476
23723
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7477 #ifdef FEAT_PROFILE
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7478 if (cctx->ctx_profiling)
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7479 {
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7480 if (cctx->ctx_skip == SKIP_NOT
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7481 && ((isn_T *)instr->ga_data)[instr->ga_len - 1]
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7482 .isn_type == ISN_PROF_START)
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7483 // the previous block was executed, do not count "else" for profiling
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7484 --instr->ga_len;
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7485 if (cctx->ctx_skip == SKIP_YES && !scope->se_u.se_if.is_seen_skip_not)
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7486 {
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7487 // the previous block was not executed, this one will, do count the
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7488 // "else" for profiling
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7489 cctx->ctx_skip = SKIP_NOT;
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7490 generate_instr(cctx, ISN_PROF_END);
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7491 generate_instr(cctx, ISN_PROF_START);
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7492 cctx->ctx_skip = SKIP_YES;
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7493 }
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7494 }
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7495 #endif
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7496
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7497 if (!scope->se_u.se_if.is_seen_skip_not && scope->se_skip_save != SKIP_YES)
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7498 {
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7499 // 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
7500 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
7501 {
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7502 if (!cctx->ctx_had_return
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7503 && 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
7504 JUMP_ALWAYS, cctx) == FAIL)
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7505 return NULL;
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7506 }
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7507
20933
e2fd5f05342f patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents: 20929
diff changeset
7508 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
7509 {
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7510 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
7511 {
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7512 // 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
7513 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
7514 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
7515 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
7516 }
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7517 }
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7518
20933
e2fd5f05342f patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents: 20929
diff changeset
7519 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
7520 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
7521 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7522
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7523 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7524 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7525
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7526 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7527 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
7528 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7529 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
7530 ifscope_T *ifscope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7531 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
7532 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7533
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
7534 if (misplaced_cmdmod(cctx))
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
7535 return NULL;
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
7536
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7537 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
7538 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7539 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
7540 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7541 }
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
7542 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
7543 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
7544 if (!cctx->ctx_had_return)
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7545 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
7546
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7547 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
7548 {
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7549 // 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
7550 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
7551 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
7552 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7553 // Fill in the "end" label in jumps at the end of the blocks.
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
7554 compile_fill_jump_to_end(&ifscope->is_end_label, instr->ga_len, cctx);
23723
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7555
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7556 #ifdef FEAT_PROFILE
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7557 // even when skipping we count the endif as executed, unless the block it's
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7558 // in is skipped
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7559 if (cctx->ctx_profiling && cctx->ctx_skip == SKIP_YES
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7560 && scope->se_skip_save != SKIP_YES)
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7561 {
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7562 cctx->ctx_skip = SKIP_NOT;
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7563 generate_instr(cctx, ISN_PROF_START);
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7564 }
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7565 #endif
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7566 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
7567
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7568 // 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
7569 // had_return flag is set.
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7570 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
7571
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7572 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
7573 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7574 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7575
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7576 /*
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7577 * 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
7578 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7579 * Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7580 * PUSHNR -1
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7581 * 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
7582 * 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
7583 * 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
7584 * - 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
7585 * - 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
7586 * 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
7587 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7588 * 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
7589 * 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
7590 *
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7591 * 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
7592 * 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
7593 * 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
7594 * 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
7595 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7596 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
7597 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
7598 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7599 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
7600 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
7601 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
7602 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
7603 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
7604 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
7605 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
7606 size_t varlen;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7607 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
7608 scope_T *scope;
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
7609 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
7610 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
7611 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
7612 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
7613 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
7614
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7615 p = skip_var_list(arg_start, TRUE, &var_count, &semicolon, FALSE);
23658
c8f26523d7d7 patch 8.2.2371: Vim9: crash when using types in :for with unpack
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
7616 if (p == NULL)
c8f26523d7d7 patch 8.2.2371: Vim9: crash when using types in :for with unpack
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
7617 return NULL;
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7618 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
7619 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
7620
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7621 // 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
7622 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
7623 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
7624 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
7625 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
7626 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7627 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
7628 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7629 }
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
7630 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
7631 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
7632 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7633
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7634 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
7635 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7636 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7637
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7638 // 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
7639 // to -1.
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
7640 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
7641 if (loop_lvar == NULL)
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
7642 {
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
7643 // out of memory
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7644 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
7645 return NULL;
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7646 }
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
7647 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
7648
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7649 // 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
7650 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
7651 if (compile_expr0(&arg, cctx) == FAIL)
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7652 {
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7653 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
7654 return NULL;
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7655 }
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7656 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
7657
24480
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
7658 // If we know the type of "var" and it is a not a supported type we can
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
7659 // give an error now.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7660 vartype = ((type_T **)stack->ga_data)[stack->ga_len - 1];
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
7661 if (vartype->tt_type != VAR_LIST && vartype->tt_type != VAR_STRING
24480
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
7662 && vartype->tt_type != VAR_BLOB && vartype->tt_type != VAR_ANY)
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
7663 {
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
7664 semsg(_(e_for_loop_on_str_not_supported),
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
7665 vartype_name(vartype->tt_type));
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7666 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
7667 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7668 }
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7669
24460
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7670 if (vartype->tt_type == VAR_STRING)
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7671 item_type = &t_string;
24480
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
7672 else if (vartype->tt_type == VAR_BLOB)
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
7673 item_type = &t_number;
24460
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7674 else if (vartype->tt_type == VAR_LIST
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7675 && 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
7676 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7677 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
7678 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
7679 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
7680 && vartype->tt_member->tt_member->tt_type != VAR_ANY)
24480
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
7681 // TODO: should get the type for each lhs
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7682 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
7683 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7684
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7685 // CMDMOD_REV must come before the FOR instruction
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7686 generate_undo_cmdmods(cctx);
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7687
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7688 // "for_end" is set when ":endfor" is found
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7689 scope->se_u.se_for.fs_top_label = current_instr_idx(cctx);
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
7690 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
7691
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7692 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
7693 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
7694 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7695 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
7696 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
7697
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7698 // 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
7699 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
7700 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7701 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
7702 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
7703 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7704 --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
7705 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
7706 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7707 ((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
7708 (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
7709 ++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
7710 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7711 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7712
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7713 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
7714 {
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7715 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
7716 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
7717 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
7718 type_T *type = &t_any;
24460
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7719 type_T *lhs_type = &t_any;
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7720 where_T where;
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7721
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7722 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
7723 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
7724 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
7725 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
7726 goto failed;
24460
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7727 if (*p == ':')
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7728 {
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7729 p = skipwhite(p + 1);
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7730 lhs_type = parse_type(&p, cctx->ctx_type_list, TRUE);
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7731 }
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7732
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7733 // 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
7734 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
7735 &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
7736 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
7737 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
7738 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7739 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
7740 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
7741 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
7742 }
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7743 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
7744 {
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
7745 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
7746 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7747 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
7748 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
7749 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7750
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
7751 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
7752 {
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
7753 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
7754 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
7755 }
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
7756
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7757 // Reserve a variable to store "var".
24460
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7758 where.wt_index = var_count > 1 ? idx + 1 : 0;
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7759 where.wt_variable = TRUE;
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7760 if (lhs_type == &t_any)
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7761 lhs_type = item_type;
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7762 else if (item_type != &t_unknown
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7763 && !(var_count > 1 && item_type == &t_any)
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7764 && check_type(lhs_type, item_type, TRUE, where) == FAIL)
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7765 goto failed;
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7766 var_lvar = reserve_local(cctx, arg, varlen, TRUE, lhs_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
7767 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
7768 // 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
7769 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
7770
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7771 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
7772 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
7773 else
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7774 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
7775 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
7776 }
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7777
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7778 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
7779 ++p;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7780 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
7781 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
7782 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7783
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7784 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
7785
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7786 failed:
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7787 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
7788 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
7789 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7790 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7791
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7792 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7793 * compile "endfor"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7794 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7795 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7796 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
7797 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7798 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
7799 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
7800 forscope_T *forscope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7801 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7802
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
7803 if (misplaced_cmdmod(cctx))
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
7804 return NULL;
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7805
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7806 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
7807 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7808 emsg(_(e_for));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7809 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7810 }
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
7811 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
7812 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
7813 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
7814
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7815 // 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
7816 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
7817
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7818 // 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
7819 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
7820 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
7821
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7822 // Fill in the "end" label any BREAK statements
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
7823 compile_fill_jump_to_end(&forscope->fs_end_label, instr->ga_len, cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7824
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7825 // 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
7826 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
7827 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7828
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7829 vim_free(scope);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7830
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7831 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7832 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7833
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7834 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7835 * compile "while expr"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7836 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7837 * Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7838 * 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
7839 * 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
7840 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7841 * 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
7842 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7843 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7844 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7845 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7846 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
7847 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7848 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
7849 scope_T *scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7850
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7851 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
7852 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7853 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7854
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7855 // "endwhile" jumps back here, one before when profiling or using cmdmods
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7856 scope->se_u.se_while.ws_top_label = current_instr_idx(cctx);
19181
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 // 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
7859 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
7860 return NULL;
23882
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7861 if (!ends_excmd2(arg, skipwhite(p)))
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7862 {
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7863 semsg(_(e_trailing_arg), p);
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7864 return NULL;
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7865 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7866
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7867 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
7868 return FAIL;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7869
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7870 // CMDMOD_REV must come before the jump
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7871 generate_undo_cmdmods(cctx);
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7872
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7873 // "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
7874 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
7875 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
7876 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7877
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7878 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7879 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7880
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7881 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7882 * compile "endwhile"
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 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7885 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
7886 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7887 scope_T *scope = cctx->ctx_scope;
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
7888 garray_T *instr = &cctx->ctx_instr;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7889
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
7890 if (misplaced_cmdmod(cctx))
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
7891 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7892 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
7893 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7894 emsg(_(e_while));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7895 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7896 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7897 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
7898 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
7899
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
7900 #ifdef FEAT_PROFILE
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
7901 // count the endwhile before jumping
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
7902 may_generate_prof_end(cctx, cctx->ctx_lnum);
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
7903 #endif
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
7904
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7905 // 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
7906 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
7907
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7908 // 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
7909 // And in any jumps for ":break"
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
7910 compile_fill_jump_to_end(&scope->se_u.se_while.ws_end_label,
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
7911 instr->ga_len, cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7912
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7913 vim_free(scope);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7914
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7915 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7916 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7917
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7918 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7919 * compile "continue"
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 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7922 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
7923 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7924 scope_T *scope = cctx->ctx_scope;
23927
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7925 int try_scopes = 0;
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7926 int loop_label;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7927
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7928 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7929 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7930 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7931 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7932 emsg(_(e_continue));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7933 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7934 }
23927
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7935 if (scope->se_type == FOR_SCOPE)
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7936 {
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7937 loop_label = scope->se_u.se_for.fs_top_label;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7938 break;
23927
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7939 }
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7940 if (scope->se_type == WHILE_SCOPE)
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7941 {
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7942 loop_label = scope->se_u.se_while.ws_top_label;
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7943 break;
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7944 }
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7945 if (scope->se_type == TRY_SCOPE)
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7946 ++try_scopes;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7947 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
7948 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7949
23927
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7950 if (try_scopes > 0)
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7951 // Inside one or more try/catch blocks we first need to jump to the
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7952 // "finally" or "endtry" to cleanup.
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7953 generate_TRYCONT(cctx, try_scopes, loop_label);
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7954 else
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7955 // Jump back to the FOR or WHILE instruction.
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7956 generate_JUMP(cctx, JUMP_ALWAYS, loop_label);
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7957
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7958 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7959 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7960
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7961 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7962 * compile "break"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7963 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7964 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7965 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
7966 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7967 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
7968 endlabel_T **el;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7969
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7970 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7971 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7972 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7973 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7974 emsg(_(e_break));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7975 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7976 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7977 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
7978 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7979 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
7980 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7981
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7982 // 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
7983 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
7984 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
7985 else
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
7986 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
7987 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
7988 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7989
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7990 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7991 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7992
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7993 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7994 * 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
7995 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7996 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7997 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
7998 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7999 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
8000 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8001 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
8002 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8003
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8004 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8005 * 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
8006 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8007 static void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8008 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
8009 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8010 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
8011
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8012 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
8013 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
8014 vim_free(scope);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8015 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8016
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8017 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8018 * compile "try"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8019 * 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
8020 * finally.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8021 * 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
8022 * 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
8023 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8024 * "try"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8025 * 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
8026 * ... try block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8027 * "throw {exception}"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8028 * EVAL {exception}
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8029 * THROW create exception
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8030 * ... try block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8031 * " catch {expr}"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8032 * JUMP -> finally
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 23199
diff changeset
8033 * 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
8034 * EVAL {expr}
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8035 * MATCH
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8036 * JUMP nomatch -> catch2
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8037 * CATCH remove exception
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8038 * ... catch block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8039 * " catch"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8040 * JUMP -> finally
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8041 * 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
8042 * ... catch block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8043 * " finally"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8044 * finally:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8045 * ... finally block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8046 * " endtry"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8047 * 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
8048 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8049 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8050 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
8051 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8052 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
8053 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
8054 scope_T *scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8055
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8056 if (misplaced_cmdmod(cctx))
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8057 return NULL;
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8058
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8059 // 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
8060 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
8061 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
8062 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8063
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8064 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
8065 {
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8066 isn_T *isn;
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8067
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8068 // "try_catch" is set when the first ":catch" is found or when no catch
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8069 // is found and ":finally" is found.
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8070 // "try_finally" is set when ":finally" is found
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8071 // "try_endtry" is set when ":endtry" is found
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8072 try_scope->se_u.se_try.ts_try_label = instr->ga_len;
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8073 if ((isn = generate_instr(cctx, ISN_TRY)) == NULL)
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8074 return NULL;
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8075 isn->isn_arg.try.try_ref = ALLOC_CLEAR_ONE(tryref_T);
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8076 if (isn->isn_arg.try.try_ref == NULL)
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8077 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
8078 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8079
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8080 // 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
8081 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
8082 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8083 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8084
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8085 return arg;
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8089 * compile "catch {expr}"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8090 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8091 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8092 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
8093 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8094 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
8095 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
8096 char_u *p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8097 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8098
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8099 if (misplaced_cmdmod(cctx))
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8100 return NULL;
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8101
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8102 // 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
8103 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
8104 compile_endblock(cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8105 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
8106
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8107 // 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
8108 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
8109 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8110 emsg(_(e_catch));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8111 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8112 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8113
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
8114 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
8115 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
8116 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
8117 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8118 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8119
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8120 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
8121 {
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8122 #ifdef FEAT_PROFILE
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8123 // the profile-start should be after the jump
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8124 if (cctx->ctx_profiling && ((isn_T *)instr->ga_data)[instr->ga_len - 1]
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8125 .isn_type == ISN_PROF_START)
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8126 --instr->ga_len;
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8127 #endif
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8128 // 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
8129 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
8130 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
8131 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
8132
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8133 // 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
8134 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_try_label;
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8135 if (isn->isn_arg.try.try_ref->try_catch == 0)
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8136 isn->isn_arg.try.try_ref->try_catch = instr->ga_len;
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8137 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
8138 {
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8139 // 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
8140 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
8141 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
8142 }
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8143 #ifdef FEAT_PROFILE
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8144 if (cctx->ctx_profiling)
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8145 {
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8146 // a "throw" that jumps here needs to be counted
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8147 generate_instr(cctx, ISN_PROF_END);
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8148 // the "catch" is also counted
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8149 generate_instr(cctx, ISN_PROF_START);
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8150 }
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8151 #endif
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8152 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8153
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8154 p = skipwhite(arg);
20059
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20055
diff changeset
8155 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
8156 {
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
8157 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
8158 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
8159 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8160 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8161 {
19316
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8162 char_u *end;
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8163 char_u *pat;
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8164 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
8165 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
8166 int len;
19316
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8167
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8168 // 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
8169 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
8170
23505
bb29b09902d5 patch 8.2.2295: incsearch does not detect empty pattern properly
Bram Moolenaar <Bram@vim.org>
parents: 23497
diff changeset
8171 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
8172 if (*end != *p)
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8173 {
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
8174 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
8175 vim_free(tofree);
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8176 return FAIL;
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8177 }
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8178 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
8179 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
8180 else
19892
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19884
diff changeset
8181 len = (int)(end - tofree);
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19884
diff changeset
8182 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
8183 vim_free(tofree);
19892
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19884
diff changeset
8184 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
8185 if (pat == NULL)
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8186 return FAIL;
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8187 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
8188 return FAIL;
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8189
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8190 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
8191 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8192
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
8193 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
8194 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
8195 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8196 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8197
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8198 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
8199 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8200
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8201 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
8202 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8203 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8204 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8205
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8206 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8207 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
8208 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8209 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
8210 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
8211 isn_T *isn;
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8212 int this_instr;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8213
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8214 if (misplaced_cmdmod(cctx))
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8215 return NULL;
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8216
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8217 // 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
8218 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
8219 compile_endblock(cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8220 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
8221
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8222 // 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
8223 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
8224 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8225 emsg(_(e_finally));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8226 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8227 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8228
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8229 // 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
8230 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_try_label;
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8231 if (isn->isn_arg.try.try_ref->try_finally != 0)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8232 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8233 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
8234 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8235 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8236
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8237 this_instr = instr->ga_len;
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8238 #ifdef FEAT_PROFILE
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8239 if (cctx->ctx_profiling && ((isn_T *)instr->ga_data)[instr->ga_len - 1]
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8240 .isn_type == ISN_PROF_START)
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8241 // jump to the profile start of the "finally"
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8242 --this_instr;
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8243 #endif
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8244
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8245 // Fill in the "end" label in jumps at the end of the blocks.
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8246 compile_fill_jump_to_end(&scope->se_u.se_try.ts_end_label,
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8247 this_instr, cctx);
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8248
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8249 // If there is no :catch then an exception jumps to :finally.
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8250 if (isn->isn_arg.try.try_ref->try_catch == 0)
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8251 isn->isn_arg.try.try_ref->try_catch = this_instr;
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8252 isn->isn_arg.try.try_ref->try_finally = this_instr;
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
8253 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
8254 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8255 // 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
8256 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_catch_label;
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8257 isn->isn_arg.jump.jump_where = this_instr;
21371
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21353
diff changeset
8258 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
8259 }
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8260 if (generate_instr(cctx, ISN_FINALLY) == NULL)
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8261 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8262
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8263 // 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
8264
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8265 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8266 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8267
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8268 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8269 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
8270 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8271 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
8272 garray_T *instr = &cctx->ctx_instr;
23927
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
8273 isn_T *try_isn;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8274
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8275 if (misplaced_cmdmod(cctx))
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8276 return NULL;
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8277
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8278 // 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
8279 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
8280 compile_endblock(cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8281 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
8282
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8283 // 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
8284 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
8285 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8286 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8287 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
8288 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
8289 emsg(_(e_endwhile));
19213
b18437efabac patch 8.2.0165: Coverity warning for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents: 19193
diff changeset
8290 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
8291 emsg(_(e_endfor));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8292 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8293 emsg(_(e_endif));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8294 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8295 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8296
23927
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
8297 try_isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_try_label;
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8298 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
8299 {
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8300 if (try_isn->isn_arg.try.try_ref->try_catch == 0
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8301 && try_isn->isn_arg.try.try_ref->try_finally == 0)
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8302 {
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8303 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
8304 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
8305 }
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8306
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8307 #ifdef FEAT_PROFILE
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8308 if (cctx->ctx_profiling && ((isn_T *)instr->ga_data)[instr->ga_len - 1]
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8309 .isn_type == ISN_PROF_START)
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8310 // move the profile start after "endtry" so that it's not counted when
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8311 // the exception is rethrown.
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8312 --instr->ga_len;
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8313 #endif
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8314
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8315 // 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
8316 // done by ":finally".
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8317 compile_fill_jump_to_end(&scope->se_u.se_try.ts_end_label,
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8318 instr->ga_len, cctx);
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8319
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8320 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
8321 {
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8322 // Last catch without match jumps here
23927
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
8323 isn_T *isn = ((isn_T *)instr->ga_data)
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
8324 + scope->se_u.se_try.ts_catch_label;
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8325 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
8326 }
21371
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21353
diff changeset
8327 }
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21353
diff changeset
8328
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8329 compile_endblock(cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8330
23948
9854b4c6d5e6 patch 8.2.2516: test failure on s390
Bram Moolenaar <Bram@vim.org>
parents: 23927
diff changeset
8331 if (cctx->ctx_skip != SKIP_YES)
9854b4c6d5e6 patch 8.2.2516: test failure on s390
Bram Moolenaar <Bram@vim.org>
parents: 23927
diff changeset
8332 {
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8333 // End :catch or :finally scope: set instruction index in ISN_TRY
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8334 // instruction
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8335 try_isn->isn_arg.try.try_ref->try_endtry = instr->ga_len;
23948
9854b4c6d5e6 patch 8.2.2516: test failure on s390
Bram Moolenaar <Bram@vim.org>
parents: 23927
diff changeset
8336 if (cctx->ctx_skip != SKIP_YES
9854b4c6d5e6 patch 8.2.2516: test failure on s390
Bram Moolenaar <Bram@vim.org>
parents: 23927
diff changeset
8337 && generate_instr(cctx, ISN_ENDTRY) == NULL)
9854b4c6d5e6 patch 8.2.2516: test failure on s390
Bram Moolenaar <Bram@vim.org>
parents: 23927
diff changeset
8338 return NULL;
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8339 #ifdef FEAT_PROFILE
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8340 if (cctx->ctx_profiling)
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8341 generate_instr(cctx, ISN_PROF_START);
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8342 #endif
23948
9854b4c6d5e6 patch 8.2.2516: test failure on s390
Bram Moolenaar <Bram@vim.org>
parents: 23927
diff changeset
8343 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8344 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8345 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8346
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8347 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8348 * compile "throw {expr}"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8349 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8350 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8351 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
8352 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8353 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
8354
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
8355 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
8356 return NULL;
23576
4cd173b3d572 patch 8.2.2330: Vim9: crash when using :trow in a not executed block
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
8357 if (cctx->ctx_skip == SKIP_YES)
4cd173b3d572 patch 8.2.2330: Vim9: crash when using :trow in a not executed block
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
8358 return p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8359 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
8360 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8361 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
8362 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8363
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8364 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8365 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8366
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8367 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8368 * 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
8369 * 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
8370 * 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
8371 * 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
8372 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8373 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
8374 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
8375 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8376 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
8377 char_u *prev = arg;
24614
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24608
diff changeset
8378 char_u *expr_start;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8379 int count = 0;
24471
baf75c8e1b7b patch 8.2.2775: Vim9: wrong line number used for some commands
Bram Moolenaar <Bram@vim.org>
parents: 24460
diff changeset
8380 int start_ctx_lnum = cctx->ctx_lnum;
24614
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24608
diff changeset
8381 garray_T *stack = &cctx->ctx_type_stack;
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24608
diff changeset
8382 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
8383
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
8384 for (;;)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8385 {
23183
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
8386 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
8387 break;
24614
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24608
diff changeset
8388 expr_start = 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
8389 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
8390 return NULL;
24614
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24608
diff changeset
8391
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24608
diff changeset
8392 if (cctx->ctx_skip != SKIP_YES)
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24608
diff changeset
8393 {
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24608
diff changeset
8394 // check for non-void type
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24608
diff changeset
8395 type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24608
diff changeset
8396 if (type->tt_type == VAR_VOID)
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24608
diff changeset
8397 {
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24608
diff changeset
8398 semsg(_(e_expression_does_not_result_in_value_str), expr_start);
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24608
diff changeset
8399 return NULL;
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24608
diff changeset
8400 }
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24608
diff changeset
8401 }
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24608
diff changeset
8402
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8403 ++count;
21835
b530ead4265a patch 8.2.1467: Vim9: :echomsg doesn't like a dict argument
Bram Moolenaar <Bram@vim.org>
parents: 21833
diff changeset
8404 prev = p;
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
8405 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
8406 }
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
8407
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
8408 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
8409 {
24471
baf75c8e1b7b patch 8.2.2775: Vim9: wrong line number used for some commands
Bram Moolenaar <Bram@vim.org>
parents: 24460
diff changeset
8410 long save_lnum = cctx->ctx_lnum;
baf75c8e1b7b patch 8.2.2775: Vim9: wrong line number used for some commands
Bram Moolenaar <Bram@vim.org>
parents: 24460
diff changeset
8411
baf75c8e1b7b patch 8.2.2775: Vim9: wrong line number used for some commands
Bram Moolenaar <Bram@vim.org>
parents: 24460
diff changeset
8412 // Use the line number where the command started.
baf75c8e1b7b patch 8.2.2775: Vim9: wrong line number used for some commands
Bram Moolenaar <Bram@vim.org>
parents: 24460
diff changeset
8413 cctx->ctx_lnum = start_ctx_lnum;
baf75c8e1b7b patch 8.2.2775: Vim9: wrong line number used for some commands
Bram Moolenaar <Bram@vim.org>
parents: 24460
diff changeset
8414
23183
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
8415 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
8416 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
8417 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
8418 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
8419 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
8420 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
8421 else
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
8422 generate_MULT_EXPR(cctx, ISN_ECHOERR, count);
24471
baf75c8e1b7b patch 8.2.2775: Vim9: wrong line number used for some commands
Bram Moolenaar <Bram@vim.org>
parents: 24460
diff changeset
8423
baf75c8e1b7b patch 8.2.2775: Vim9: wrong line number used for some commands
Bram Moolenaar <Bram@vim.org>
parents: 24460
diff changeset
8424 cctx->ctx_lnum = save_lnum;
23183
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
8425 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8426 return p;
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
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8429 /*
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 23199
diff changeset
8430 * 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
8431 * 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
8432 * 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
8433 */
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8434 static int
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8435 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
8436 {
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8437 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
8438 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
8439
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8440 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
8441 return FAIL;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8442 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
8443 }
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8444
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8445 /*
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8446 * :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
8447 * :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
8448 */
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8449 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
8450 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
8451 {
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8452 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
8453 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
8454 char *errormsg;
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
8455 int above = eap->forceit;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
8456
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8457 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
8458
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8459 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
8460 {
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8461 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
8462
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8463 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
8464 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
8465 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
8466 }
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8467 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
8468 ++line;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8469
23156
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8470 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
8471 {
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8472 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
8473 }
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8474 else
23156
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8475 {
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8476 // 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
8477 // "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
8478 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
8479 // 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
8480 return NULL;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8481 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
8482 lnum = -1;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8483 else
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8484 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
8485 if (above)
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8486 --lnum;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8487 }
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8488
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8489 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
8490 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
8491 }
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8492
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8493 /*
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8494 * 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
8495 */
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8496 static char_u *
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8497 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
8498 {
20172
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
8499 char_u *p;
20174
72b437855299 patch 8.2.0642: Vim9: using invalid index
Bram Moolenaar <Bram@vim.org>
parents: 20172
diff changeset
8500 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
8501 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
8502
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
8503 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
8504 goto theend;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8505
20174
72b437855299 patch 8.2.0642: Vim9: using invalid index
Bram Moolenaar <Bram@vim.org>
parents: 20172
diff changeset
8506 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
8507 {
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
8508 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
8509 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
8510
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8511 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
8512
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8513 // 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
8514 // 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
8515 // 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
8516 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
8517 && *eap->arg == '!')
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8518 // :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
8519 usefilter = TRUE;
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8520 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
8521 {
21893
f19ac9b8b011 patch 8.2.1496: Vim9: cannot use " #" in a mapping
Bram Moolenaar <Bram@vim.org>
parents: 21883
diff changeset
8522 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
8523 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
8524 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
8525 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
8526 }
23477
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8527 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
8528 {
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8529 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
8530 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
8531 ++p;
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8532 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
8533 ++p;
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8534 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
8535 if (*p == '|')
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8536 {
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8537 *p = NUL;
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8538 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
8539 }
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8540 }
21156
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8541 }
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8542
20172
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
8543 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
8544 {
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
8545 // 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
8546 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
8547 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
8548 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
8549 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
8550 }
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
8551
23344
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8552 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
8553 && STRLEN(eap->arg) > 4)
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8554 {
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8555 int delim = *eap->arg;
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8556
23505
bb29b09902d5 patch 8.2.2295: incsearch does not detect empty pattern properly
Bram Moolenaar <Bram@vim.org>
parents: 23497
diff changeset
8557 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
8558 if (*p == delim)
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8559 {
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8560 eap->arg = p + 1;
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8561 has_expr = TRUE;
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8562 }
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8563 }
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8564
23521
0ef920a03380 patch 8.2.2303: Vim9: backtick expansion doesn't work for :foldopen
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
8565 if (eap->cmdidx == CMD_folddoopen || eap->cmdidx == CMD_folddoclosed)
0ef920a03380 patch 8.2.2303: Vim9: backtick expansion doesn't work for :foldopen
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
8566 {
0ef920a03380 patch 8.2.2303: Vim9: backtick expansion doesn't work for :foldopen
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
8567 // TODO: should only expand when appropriate for the command
0ef920a03380 patch 8.2.2303: Vim9: backtick expansion doesn't work for :foldopen
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
8568 eap->arg = skiptowhite(eap->arg);
0ef920a03380 patch 8.2.2303: Vim9: backtick expansion doesn't work for :foldopen
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
8569 has_expr = TRUE;
0ef920a03380 patch 8.2.2303: Vim9: backtick expansion doesn't work for :foldopen
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
8570 }
0ef920a03380 patch 8.2.2303: Vim9: backtick expansion doesn't work for :foldopen
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
8571
20172
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
8572 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
8573 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8574 int count = 0;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8575 char_u *start = skipwhite(line);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8576
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8577 // :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
8578 // PUSHS ":cmd xxx"
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8579 // eval expr1
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8580 // PUSHS "yyy"
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8581 // eval expr2
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8582 // PUSHS "zzz"
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8583 // EXECCONCAT 5
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8584 for (;;)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8585 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8586 if (p > start)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8587 {
20830
9064044fd4f6 patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
8588 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
8589 ++count;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8590 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8591 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
8592 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
8593 return NULL;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8594 may_generate_2STRING(-1, cctx);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8595 ++count;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8596 p = skipwhite(p);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8597 if (*p != '`')
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8598 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
8599 emsg(_(e_missing_backtick));
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8600 return NULL;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8601 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8602 start = p + 1;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8603
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8604 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
8605 if (p == NULL)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8606 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8607 if (*skipwhite(start) != NUL)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8608 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8609 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
8610 ++count;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8611 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8612 break;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8613 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8614 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8615 generate_EXECCONCAT(cctx, count);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8616 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8617 else
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8618 generate_EXEC(cctx, line);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8619
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8620 theend:
21156
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8621 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
8622 {
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8623 // 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
8624 --nextcmd;
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8625 *nextcmd = '|';
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8626 }
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8627
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8628 return nextcmd;
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8629 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8630
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8631
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8632 /*
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8633 * :s/pat/repl/
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8634 */
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8635 static char_u *
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8636 compile_substitute(char_u *arg, exarg_T *eap, cctx_T *cctx)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8637 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8638 char_u *cmd = eap->arg;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8639 char_u *expr = (char_u *)strstr((char *)cmd, "\\=");
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8640
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8641 if (expr != NULL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8642 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8643 int delimiter = *cmd++;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8644
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8645 // There is a \=expr, find it in the substitute part.
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8646 cmd = skip_regexp_ex(cmd, delimiter, magic_isset(), NULL, NULL, NULL);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8647 if (cmd[0] == delimiter && cmd[1] == '\\' && cmd[2] == '=')
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8648 {
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8649 garray_T save_ga = cctx->ctx_instr;
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8650 char_u *end;
24510
b5786b4de9d1 patch 8.2.2795: Coverity warns for not using return value
Bram Moolenaar <Bram@vim.org>
parents: 24502
diff changeset
8651 int expr_res;
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8652 int trailing_error;
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8653 int instr_count;
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
8654 isn_T *instr;
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8655 isn_T *isn;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8656
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8657 cmd += 3;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8658 end = skip_substitute(cmd, delimiter);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8659
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
8660 // Temporarily reset the list of instructions so that the jump
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8661 // labels are correct.
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8662 cctx->ctx_instr.ga_len = 0;
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8663 cctx->ctx_instr.ga_maxlen = 0;
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8664 cctx->ctx_instr.ga_data = NULL;
24510
b5786b4de9d1 patch 8.2.2795: Coverity warns for not using return value
Bram Moolenaar <Bram@vim.org>
parents: 24502
diff changeset
8665 expr_res = compile_expr0(&cmd, cctx);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8666 if (end[-1] == NUL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8667 end[-1] = delimiter;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8668 cmd = skipwhite(cmd);
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8669 trailing_error = *cmd != delimiter && *cmd != NUL;
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8670
24510
b5786b4de9d1 patch 8.2.2795: Coverity warns for not using return value
Bram Moolenaar <Bram@vim.org>
parents: 24502
diff changeset
8671 if (expr_res == FAIL || trailing_error
b5786b4de9d1 patch 8.2.2795: Coverity warns for not using return value
Bram Moolenaar <Bram@vim.org>
parents: 24502
diff changeset
8672 || ga_grow(&cctx->ctx_instr, 1) == FAIL)
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8673 {
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8674 if (trailing_error)
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8675 semsg(_(e_trailing_arg), cmd);
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8676 clear_instr_ga(&cctx->ctx_instr);
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8677 cctx->ctx_instr = save_ga;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8678 return NULL;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8679 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8680
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8681 // Move the generated instructions into the ISN_SUBSTITUTE
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8682 // instructions, then restore the list of instructions before
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8683 // adding the ISN_SUBSTITUTE instruction.
24502
5baac0b4b41c patch 8.2.2791: Vim9: memory leak when using =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24498
diff changeset
8684 instr_count = cctx->ctx_instr.ga_len;
5baac0b4b41c patch 8.2.2791: Vim9: memory leak when using =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24498
diff changeset
8685 instr = cctx->ctx_instr.ga_data;
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8686 instr[instr_count].isn_type = ISN_FINISH;
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8687
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8688 cctx->ctx_instr = save_ga;
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8689 if ((isn = generate_instr(cctx, ISN_SUBSTITUTE)) == NULL)
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8690 {
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8691 int idx;
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8692
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8693 for (idx = 0; idx < instr_count; ++idx)
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8694 delete_instr(instr + idx);
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8695 vim_free(instr);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8696 return NULL;
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8697 }
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8698 isn->isn_arg.subs.subs_cmd = vim_strsave(arg);
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8699 isn->isn_arg.subs.subs_instr = instr;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8700
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8701 // skip over flags
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8702 if (*end == '&')
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8703 ++end;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8704 while (ASCII_ISALPHA(*end) || *end == '#')
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8705 ++end;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8706 return end;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8707 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8708 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8709
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8710 return compile_exec(arg, eap, cctx);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8711 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8712
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8713 static char_u *
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8714 compile_redir(char_u *line, exarg_T *eap, cctx_T *cctx)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8715 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8716 char_u *arg = eap->arg;
24512
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8717 lhs_T *lhs = &cctx->ctx_redir_lhs;
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8718
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8719 if (lhs->lhs_name != NULL)
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8720 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8721 if (STRNCMP(arg, "END", 3) == 0)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8722 {
24512
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8723 if (lhs->lhs_append)
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8724 {
24516
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
8725 // First load the current variable value.
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
8726 if (compile_load_lhs_with_index(lhs, lhs->lhs_whole,
056f954c6fd2 patch 8.2.2798: Vim9: redir to variable with append does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24512
diff changeset
8727 cctx) == FAIL)
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8728 return NULL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8729 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8730
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8731 // Gets the redirected text and put it on the stack, then store it
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8732 // in the variable.
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8733 generate_instr_type(cctx, ISN_REDIREND, &t_string);
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8734
24512
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8735 if (lhs->lhs_append)
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8736 generate_instr_drop(cctx, ISN_CONCAT, 1);
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8737
24512
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8738 if (lhs->lhs_has_index)
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8739 {
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8740 // Use the info in "lhs" to store the value at the index in the
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8741 // list or dict.
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8742 if (compile_assign_unlet(lhs->lhs_whole, lhs, TRUE,
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8743 &t_string, cctx) == FAIL)
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8744 return NULL;
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8745 }
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8746 else if (generate_store_lhs(cctx, lhs, -1) == FAIL)
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8747 return NULL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8748
24512
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8749 VIM_CLEAR(lhs->lhs_name);
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8750 VIM_CLEAR(lhs->lhs_whole);
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8751 return arg + 3;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8752 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8753 emsg(_(e_cannot_nest_redir));
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8754 return NULL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8755 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8756
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8757 if (arg[0] == '=' && arg[1] == '>')
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8758 {
24512
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8759 int append = FALSE;
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8760
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8761 // redirect to a variable is compiled
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8762 arg += 2;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8763 if (*arg == '>')
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8764 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8765 ++arg;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8766 append = TRUE;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8767 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8768 arg = skipwhite(arg);
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8769
24512
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8770 if (compile_assign_lhs(arg, lhs, CMD_redir,
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8771 FALSE, FALSE, 1, cctx) == FAIL)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8772 return NULL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8773 generate_instr(cctx, ISN_REDIRSTART);
24512
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8774 lhs->lhs_append = append;
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8775 if (lhs->lhs_has_index)
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8776 {
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8777 lhs->lhs_whole = vim_strnsave(arg, lhs->lhs_varlen_total);
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8778 if (lhs->lhs_whole == NULL)
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8779 return NULL;
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8780 }
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8781
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8782 return arg + lhs->lhs_varlen_total;
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8783 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8784
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8785 // other redirects are handled like at script level
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8786 return compile_exec(line, eap, cctx);
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8787 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8788
24594
5c456a88f651 patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents: 24592
diff changeset
8789 #ifdef FEAT_QUICKFIX
24590
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8790 static char_u *
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8791 compile_cexpr(char_u *line, exarg_T *eap, cctx_T *cctx)
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8792 {
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8793 isn_T *isn;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8794 char_u *p;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8795
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8796 isn = generate_instr(cctx, ISN_CEXPR_AUCMD);
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8797 if (isn == NULL)
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8798 return NULL;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8799 isn->isn_arg.number = eap->cmdidx;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8800
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8801 p = eap->arg;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8802 if (compile_expr0(&p, cctx) == FAIL)
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8803 return NULL;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8804
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8805 isn = generate_instr(cctx, ISN_CEXPR_CORE);
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8806 if (isn == NULL)
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8807 return NULL;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8808 isn->isn_arg.cexpr.cexpr_ref = ALLOC_ONE(cexprref_T);
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8809 if (isn->isn_arg.cexpr.cexpr_ref == NULL)
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8810 return NULL;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8811 isn->isn_arg.cexpr.cexpr_ref->cer_cmdidx = eap->cmdidx;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8812 isn->isn_arg.cexpr.cexpr_ref->cer_forceit = eap->forceit;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8813 isn->isn_arg.cexpr.cexpr_ref->cer_cmdline = vim_strsave(skipwhite(line));
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8814
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8815 return p;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8816 }
24594
5c456a88f651 patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents: 24592
diff changeset
8817 #endif
24590
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8818
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8819 /*
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
8820 * 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
8821 * 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
8822 */
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20419
diff changeset
8823 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
8824 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
8825 {
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
8826 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
8827
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
8828 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
8829 {
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
8830 // 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
8831 // 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
8832 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
8833 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
8834 ++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
8835 }
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
8836
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
8837 // 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
8838 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
8839 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
8840 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
8841 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
8842 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
8843 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
8844 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
8845 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
8846 ++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
8847 ++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
8848 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
8849 }
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
8850
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
8851 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8852 * 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
8853 * 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
8854 * 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
8855 * 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
8856 * 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
8857 * then check that it matches.
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8858 * When "profiling" is true add ISN_PROF_START instructions.
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
8859 * "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
8860 * 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
8861 * "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
8862 * 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
8863 */
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20419
diff changeset
8864 int
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8865 compile_def_function(
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8866 ufunc_T *ufunc,
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8867 int check_return_type,
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
8868 int profiling UNUSED,
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8869 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
8870 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8871 char_u *line = NULL;
24444
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
8872 char_u *line_to_free = NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8873 char_u *p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8874 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
8875 cctx_T cctx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8876 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
8877 int did_emsg_before = did_emsg;
24406
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
8878 int did_emsg_silent_before = did_emsg_silent;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8879 int ret = FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8880 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
8881 int save_estack_compiling = estack_compiling;
24539
3a290891a015 patch 8.2.2809: Vim9: :def function compilation fails when using :legacy
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
8882 int save_cmod_flags = cmdmod.cmod_flags;
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
8883 int do_estack_push;
21463
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
8884 int new_def_function = FALSE;
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
8885 #ifdef FEAT_PROFILE
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8886 int prof_lnum = -1;
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
8887 #endif
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8888
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
8889 // 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
8890 // 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
8891 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
8892 {
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
8893 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
8894 + 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
8895 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
8896 }
21463
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
8897 else
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
8898 {
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
8899 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
8900 return FAIL;
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
8901 new_def_function = TRUE;
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
8902 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8903
21281
13b1567ae0c6 patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
8904 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
8905
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 20005
diff changeset
8906 CLEAR_FIELD(cctx);
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8907
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
8908 #ifdef FEAT_PROFILE
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8909 cctx.ctx_profiling = profiling;
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
8910 #endif
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8911 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
8912 cctx.ctx_lnum = -1;
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
8913 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
8914 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
8915 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
8916 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
8917 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
8918 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
8919 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
8920
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
8921 // 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
8922 // 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
8923 // 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
8924 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
8925 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
8926
24539
3a290891a015 patch 8.2.2809: Vim9: :def function compilation fails when using :legacy
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
8927 // Don't use the flag from ":legacy" here.
3a290891a015 patch 8.2.2809: Vim9: :def function compilation fails when using :legacy
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
8928 cmdmod.cmod_flags &= ~CMOD_LEGACY;
3a290891a015 patch 8.2.2809: Vim9: :def function compilation fails when using :legacy
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
8929
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
8930 // 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
8931 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
8932 if (do_estack_push)
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
8933 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
8934 estack_compiling = TRUE;
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
8935
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
8936 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
8937 {
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
8938 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
8939 int first_def_arg = ufunc->uf_args.ga_len - count;
24097
26d3c1539bcc patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents: 24087
diff changeset
8940 int uf_args_len = 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
8941 int i;
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
8942 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
8943 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
8944 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
8945
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
8946 // Produce instructions for the default values of optional arguments.
24097
26d3c1539bcc patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents: 24087
diff changeset
8947 SOURCING_LNUM = 0; // line number unknown
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
8948 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
8949 {
19946
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
8950 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
8951 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
8952 int arg_idx = first_def_arg + i;
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
8953 where_T where;
24097
26d3c1539bcc patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents: 24087
diff changeset
8954 int r;
24272
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
8955 int jump_instr_idx = instr->ga_len;
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
8956 isn_T *isn;
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
8957
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
8958 // Use a JUMP_IF_ARG_SET instruction to skip if the value was given.
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
8959 if (generate_JUMP_IF_ARG_SET(&cctx, i - count - off) == FAIL)
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
8960 goto erret;
24097
26d3c1539bcc patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents: 24087
diff changeset
8961
26d3c1539bcc patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents: 24087
diff changeset
8962 // Make sure later arguments are not found.
26d3c1539bcc patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents: 24087
diff changeset
8963 ufunc->uf_args.ga_len = i;
19946
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
8964
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
8965 arg = ((char_u **)(ufunc->uf_def_args.ga_data))[i];
24097
26d3c1539bcc patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents: 24087
diff changeset
8966 r = compile_expr0(&arg, &cctx);
26d3c1539bcc patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents: 24087
diff changeset
8967
26d3c1539bcc patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents: 24087
diff changeset
8968 ufunc->uf_args.ga_len = uf_args_len;
26d3c1539bcc patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents: 24087
diff changeset
8969 if (r == FAIL)
19946
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
8970 goto erret;
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
8971
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
8972 // 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
8973 // 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
8974 // specified type.
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
8975 val_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
8976 where.wt_index = arg_idx + 1;
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
8977 where.wt_variable = FALSE;
19946
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
8978 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
8979 {
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
8980 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
8981 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
8982 }
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
8983 else if (check_type(ufunc->uf_arg_types[arg_idx], val_type,
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
8984 TRUE, where) == FAIL)
19946
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
8985 goto erret;
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
8986
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
8987 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
8988 goto erret;
24272
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
8989
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
8990 // set instruction index in JUMP_IF_ARG_SET to here
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
8991 isn = ((isn_T *)instr->ga_data) + jump_instr_idx;
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
8992 isn->isn_arg.jumparg.jump_where = instr->ga_len;
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
8993 }
21469
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
8994
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
8995 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
8996 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
8997 }
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
8998
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
8999 /*
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
9000 * 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
9001 */
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9002 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9003 {
21689
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21683
diff changeset
9004 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
9005 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
9006 char_u *cmd;
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
9007 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
9008
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
9009 // 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
9010 // 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
9011 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
9012 goto erret;
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
9013
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9014 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
9015 // 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
9016 ++line;
20949
62912ad41aff patch 8.2.1026: Vim9: cannot break the line after "->"
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
9017 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
9018 && !(*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
9019 || 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
9020 {
21455
8cc1555f2445 patch 8.2.1278: Vim9: line break after "->" only allowed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21443
diff changeset
9021 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
9022 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9023 }
24158
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
9024 else if (line != NULL && vim9_bad_comment(skipwhite(line)))
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
9025 goto erret;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9026 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9027 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
9028 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
9029 if (cctx.ctx_lnum >= ufunc->uf_lines.ga_len)
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9030 {
20055
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9031 // beyond the last line
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
9032 #ifdef FEAT_PROFILE
23723
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
9033 if (cctx.ctx_skip != SKIP_YES)
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
9034 may_generate_prof_end(&cctx, prof_lnum);
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
9035 #endif
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9036 break;
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9037 }
24444
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
9038 // Make a copy, splitting off nextcmd and removing trailing spaces
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
9039 // may change it.
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
9040 if (line != NULL)
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
9041 {
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
9042 line = vim_strsave(line);
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
9043 vim_free(line_to_free);
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
9044 line_to_free = line;
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
9045 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9046 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9047
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 20005
diff changeset
9048 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
9049 ea.cmdlinep = &line;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9050 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
9051
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9052 if (*ea.cmd == '#')
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9053 {
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9054 // "#" starts a comment
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9055 line = (char_u *)"";
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9056 continue;
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9057 }
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9058
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
9059 #ifdef FEAT_PROFILE
23723
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
9060 if (cctx.ctx_profiling && cctx.ctx_lnum != prof_lnum &&
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
9061 cctx.ctx_skip != SKIP_YES)
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9062 {
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9063 may_generate_prof_end(&cctx, prof_lnum);
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9064
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9065 prof_lnum = cctx.ctx_lnum;
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9066 generate_instr(&cctx, ISN_PROF_START);
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9067 }
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
9068 #endif
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9069
20055
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9070 // 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
9071 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
9072 {
20055
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9073 case '}':
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9074 {
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9075 // "}" 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
9076 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
9077 ? 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
9078
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9079 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
9080 {
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9081 compile_endblock(&cctx);
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9082 line = ea.cmd;
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9083 }
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9084 else
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9085 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
9086 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
9087 goto erret;
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9088 }
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9089 if (line != NULL)
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9090 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
9091 continue;
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9092 }
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9093
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9094 case '{':
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9095 // "{" 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
9096 // "{'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
9097 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
9098 {
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9099 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
9100 continue;
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9101 }
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9102 break;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9103 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9104
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9105 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9106 * COMMAND MODIFIERS
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9107 */
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
9108 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
9109 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
9110 == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9111 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9112 if (errormsg != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9113 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9114 // 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
9115 line = (char_u *)"";
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9116 continue;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9117 }
22699
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 22697
diff changeset
9118 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
9119 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
9120
22772
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
9121 // 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
9122 // 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
9123 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
9124 {
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
9125 if (*p == ':')
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
9126 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
9127 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
9128 break;
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
9129 }
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
9130
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9131 // 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
9132 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
9133 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
9134 {
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21743
diff changeset
9135 if (*ea.cmd == '(')
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21743
diff changeset
9136 // not for "call()"
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21743
diff changeset
9137 ea.cmd = p;
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21743
diff changeset
9138 else
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21743
diff changeset
9139 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
9140 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9141
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
9142 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
9143 {
23537
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
9144 int assign;
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
9145
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
9146 // Check for assignment after command modifiers.
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
9147 assign = may_compile_assignment(&ea, &line, &cctx);
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
9148 if (assign == OK)
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
9149 goto nextline;
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
9150 if (assign == FAIL)
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
9151 goto erret;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9152 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9153
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9154 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9155 * COMMAND after range
21335
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
9156 * 'text'->func() should not be confused with 'a mark
24533
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
9157 * "++nr" and "--nr" are eval commands
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9158 */
20982
bb49b5090a9c patch 8.2.1042: Vim9: cannot put an operator on the next line
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
9159 cmd = ea.cmd;
24533
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
9160 if (starts_with_colon || !(*cmd == '\''
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
9161 || (cmd[0] == cmd[1] && (*cmd == '+' || *cmd == '-'))))
20982
bb49b5090a9c patch 8.2.1042: Vim9: cannot put an operator on the next line
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
9162 {
22260
d7c1e3efa88e patch 8.2.1679: Vim9: ":*" is not recognized as a range
Bram Moolenaar <Bram@vim.org>
parents: 22236
diff changeset
9163 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
9164 if (ea.cmd > cmd)
21335
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
9165 {
21901
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
9166 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
9167 {
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
9168 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
9169 goto erret;
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
9170 }
23980
bee8c78c0c6a patch 8.2.2532: Vim9: confusing error if :k is used with a range
Bram Moolenaar <Bram@vim.org>
parents: 23978
diff changeset
9171 ea.addr_count = 1;
21901
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
9172 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
9173 {
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
9174 // 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
9175 // 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
9176 // 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
9177 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
9178 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
9179 goto nextline;
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
9180 }
21335
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
9181 }
20982
bb49b5090a9c patch 8.2.1042: Vim9: cannot put an operator on the next line
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
9182 }
24124
f4061617c438 patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents: 24116
diff changeset
9183 p = find_ex_command(&ea, NULL, starts_with_colon
f4061617c438 patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents: 24116
diff changeset
9184 ? NULL : item_exists, &cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9185
23513
872239543313 patch 8.2.2299: Vim9: invalid memory access making error message flaky
Bram Moolenaar <Bram@vim.org>
parents: 23505
diff changeset
9186 if (p == NULL)
872239543313 patch 8.2.2299: Vim9: invalid memory access making error message flaky
Bram Moolenaar <Bram@vim.org>
parents: 23505
diff changeset
9187 {
872239543313 patch 8.2.2299: Vim9: invalid memory access making error message flaky
Bram Moolenaar <Bram@vim.org>
parents: 23505
diff changeset
9188 if (cctx.ctx_skip != SKIP_YES)
872239543313 patch 8.2.2299: Vim9: invalid memory access making error message flaky
Bram Moolenaar <Bram@vim.org>
parents: 23505
diff changeset
9189 emsg(_(e_ambiguous_use_of_user_defined_command));
872239543313 patch 8.2.2299: Vim9: invalid memory access making error message flaky
Bram Moolenaar <Bram@vim.org>
parents: 23505
diff changeset
9190 goto erret;
872239543313 patch 8.2.2299: Vim9: invalid memory access making error message flaky
Bram Moolenaar <Bram@vim.org>
parents: 23505
diff changeset
9191 }
872239543313 patch 8.2.2299: Vim9: invalid memory access making error message flaky
Bram Moolenaar <Bram@vim.org>
parents: 23505
diff changeset
9192
24531
3bfec39ce31c patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 24516
diff changeset
9193 // When using ":legacy cmd" always use compile_exec().
3bfec39ce31c patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 24516
diff changeset
9194 if (local_cmdmod.cmod_flags & CMOD_LEGACY)
3bfec39ce31c patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 24516
diff changeset
9195 ea.cmdidx = CMD_legacy;
3bfec39ce31c patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 24516
diff changeset
9196
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9197 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
9198 {
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
9199 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
9200 {
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
9201 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
9202 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
9203 }
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
9204
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9205 // 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
9206 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
9207 {
23254
4b7e996354e0 patch 8.2.2173: Vim9: get internal error when assigning to undefined variable
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
9208 // 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
9209 // 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
9210 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
9211 goto erret;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9212 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9213 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9214
21957
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9215 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
9216 && 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
9217 && ea.cmdidx != CMD_else
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9218 && ea.cmdidx != CMD_endif
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9219 && ea.cmdidx != CMD_endfor
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9220 && ea.cmdidx != CMD_endwhile
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9221 && ea.cmdidx != CMD_catch
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9222 && ea.cmdidx != CMD_finally
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9223 && ea.cmdidx != CMD_endtry)
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9224 {
21957
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9225 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
9226 goto erret;
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9227 }
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9228
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9229 p = skipwhite(p);
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9230 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
9231 && 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
9232 {
22276
753452747ae5 patch 8.2.1687: Vim9: out of bounds error
Bram Moolenaar <Bram@vim.org>
parents: 22274
diff changeset
9233 if (ea.cmdidx >= 0)
753452747ae5 patch 8.2.1687: Vim9: out of bounds error
Bram Moolenaar <Bram@vim.org>
parents: 22274
diff changeset
9234 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
9235 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
9236 {
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9237 ea.forceit = TRUE;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9238 p = skipwhite(p + 1);
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9239 }
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9240 }
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9241
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9242 switch (ea.cmdidx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9243 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9244 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
9245 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
9246 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
9247 break;
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
9248
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9249 case CMD_function:
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
9250 // 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
9251 // function?
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
9252 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
9253 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9254
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9255 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
9256 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
9257 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
9258 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9259
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9260 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
9261 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
9262 break;
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
9263 case CMD_var:
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
9264 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
9265 case CMD_const:
24533
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
9266 case CMD_increment:
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
9267 case CMD_decrement:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9268 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
9269 if (line == p)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
9270 line = NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9271 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9272
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9273 case CMD_unlet:
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9274 case CMD_unlockvar:
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9275 case CMD_lockvar:
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9276 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
9277 break;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9278
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9279 case CMD_import:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9280 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
9281 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9282
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9283 case CMD_if:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9284 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
9285 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9286 case CMD_elseif:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9287 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
9288 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
9289 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9290 case CMD_else:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9291 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
9292 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
9293 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9294 case CMD_endif:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9295 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
9296 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9297
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9298 case CMD_while:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9299 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
9300 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9301 case CMD_endwhile:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9302 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
9303 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
9304 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9305
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9306 case CMD_for:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9307 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
9308 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9309 case CMD_endfor:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9310 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
9311 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
9312 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9313 case CMD_continue:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9314 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
9315 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9316 case CMD_break:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9317 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
9318 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9319
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9320 case CMD_try:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9321 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
9322 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9323 case CMD_catch:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9324 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
9325 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
9326 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9327 case CMD_finally:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9328 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
9329 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
9330 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9331 case CMD_endtry:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9332 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
9333 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
9334 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9335 case CMD_throw:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9336 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
9337 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9338
21196
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
9339 case CMD_eval:
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
9340 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
9341 goto erret;
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
9342
21957
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9343 // drop the result
21196
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
9344 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
9345
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
9346 line = skipwhite(p);
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
9347 break;
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
9348
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9349 case CMD_echo:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9350 case CMD_echon:
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
9351 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
9352 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
9353 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
9354 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
9355 break;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9356
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
9357 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
9358 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
9359 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
9360 break;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
9361
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9362 case CMD_substitute:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9363 if (cctx.ctx_skip == SKIP_YES)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9364 line = (char_u *)"";
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9365 else
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9366 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9367 ea.arg = p;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9368 line = compile_substitute(line, &ea, &cctx);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9369 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9370 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9371
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9372 case CMD_redir:
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9373 ea.arg = p;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9374 line = compile_redir(line, &ea, &cctx);
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9375 break;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9376
24590
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9377 case CMD_cexpr:
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9378 case CMD_lexpr:
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9379 case CMD_caddexpr:
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9380 case CMD_laddexpr:
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9381 case CMD_cgetexpr:
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9382 case CMD_lgetexpr:
24594
5c456a88f651 patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents: 24592
diff changeset
9383 #ifdef FEAT_QUICKFIX
24590
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9384 ea.arg = p;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9385 line = compile_cexpr(line, &ea, &cctx);
24594
5c456a88f651 patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents: 24592
diff changeset
9386 #else
5c456a88f651 patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents: 24592
diff changeset
9387 ex_ni(&ea);
5c456a88f651 patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents: 24592
diff changeset
9388 line = NULL;
5c456a88f651 patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents: 24592
diff changeset
9389 #endif
24590
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9390 break;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9391
21957
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9392 // 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
9393
21516
c7b2ce90c2de patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
9394 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
9395 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
9396 case CMD_insert:
23978
54b2aa1f0d42 patch 8.2.2531: Vim9: the :k command is obscure
Bram Moolenaar <Bram@vim.org>
parents: 23966
diff changeset
9397 case CMD_k:
21584
d0c76ce48326 patch 8.2.1342: Vim9: accidentally using "t" gives a confusing error
Bram Moolenaar <Bram@vim.org>
parents: 21578
diff changeset
9398 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
9399 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
9400 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
9401 goto erret;
c7b2ce90c2de patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
9402
21210
44611891e22c patch 8.2.1156: Vim9: No error for invalid command in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
9403 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
9404 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
9405 {
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9406 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
9407 goto erret;
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9408 }
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9409 // 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
9410 line = (char_u *)"";
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9411 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
9412
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9413 default:
21961
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
9414 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
9415 {
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
9416 // 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
9417 line = (char_u *)"";
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
9418 }
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
9419 else
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
9420 {
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
9421 // 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
9422 ea.arg = p;
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
9423 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
9424 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9425 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9426 }
21901
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
9427 nextline:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9428 if (line == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9429 goto erret;
19894
ea4f8e789627 patch 8.2.0503: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
9430 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
9431
22691
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
9432 // 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
9433 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
9434
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9435 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
9436 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9437 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
9438 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9439 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9440 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9441
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9442 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
9443 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9444 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
9445 emsg(_(e_endif));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9446 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
9447 emsg(_(e_endwhile));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9448 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
9449 emsg(_(e_endfor));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9450 else
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
9451 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
9452 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9453 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9454
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9455 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
9456 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9457 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
9458 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
9459 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
9460 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9461 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9462
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9463 // Return zero if there is no return at the end.
23543
f90e429453fd patch 8.2.2314: Vim9: returning zero takes two instructions
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
9464 generate_instr(&cctx, ISN_RETURN_ZERO);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9465 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9466
24406
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
9467 // When compiled with ":silent!" and there was an error don't consider the
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
9468 // function compiled.
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
9469 if (emsg_silent == 0 || did_emsg_silent == did_emsg_silent_before)
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
9470 {
8288884fdfe1 patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents: 19862
diff changeset
9471 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
9472 + 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
9473 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
9474 dfunc->df_script_seq = current_sctx.sc_seq;
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
9475 #ifdef FEAT_PROFILE
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9476 if (cctx.ctx_profiling)
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9477 {
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9478 dfunc->df_instr_prof = instr->ga_data;
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9479 dfunc->df_instr_prof_count = instr->ga_len;
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9480 }
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9481 else
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
9482 #endif
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9483 {
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9484 dfunc->df_instr = instr->ga_data;
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9485 dfunc->df_instr_count = instr->ga_len;
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9486 }
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
9487 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
9488 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
9489 if (cctx.ctx_outer_used)
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
9490 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
9491 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
9492 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9493
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9494 ret = OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9495
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9496 erret:
24406
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
9497 if (ufunc->uf_def_status == UF_COMPILING)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9498 {
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
9499 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
9500 + 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
9501
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
9502 clear_instr_ga(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
9503 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
9504
21463
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
9505 // 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
9506 // might as well remove it.
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
9507 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
9508 && 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
9509 {
20534
ae758aa4ee5e patch 8.2.0821: Vim9: memory leak in expr test
Bram Moolenaar <Bram@vim.org>
parents: 20532
diff changeset
9510 --def_functions.ga_len;
21463
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
9511 ufunc->uf_dfunc_idx = 0;
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
9512 }
24404
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
9513 ufunc->uf_def_status = UF_COMPILE_ERROR;
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9514
19896
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
9515 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
9516 drop_scope(&cctx);
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
9517
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9518 if (errormsg != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9519 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
9520 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
9521 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
9522 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9523
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9524 if (cctx.ctx_redir_lhs.lhs_name != NULL)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9525 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9526 if (ret == OK)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9527 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9528 emsg(_(e_missing_redir_end));
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9529 ret = FAIL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9530 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9531 vim_free(cctx.ctx_redir_lhs.lhs_name);
24512
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
9532 vim_free(cctx.ctx_redir_lhs.lhs_whole);
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9533 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9534
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9535 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
9536 estack_compiling = save_estack_compiling;
24539
3a290891a015 patch 8.2.2809: Vim9: :def function compilation fails when using :legacy
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
9537 cmdmod.cmod_flags = save_cmod_flags;
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
9538 if (do_estack_push)
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
9539 estack_pop();
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
9540
24444
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
9541 vim_free(line_to_free);
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9542 free_imported(&cctx);
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
9543 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
9544 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
9545 return ret;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9546 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9547
20532
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9548 void
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9549 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
9550 {
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9551 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
9552 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
9553
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9554 // 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
9555 // argument types.
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9556 // 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
9557 // 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
9558 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
9559 {
24061
d6489b4eb14e patch 8.2.2572: Vim9: crash when getting the types for a legacy function
Bram Moolenaar <Bram@vim.org>
parents: 24033
diff changeset
9560 if (ufunc->uf_type_list.ga_itemsize == 0)
d6489b4eb14e patch 8.2.2572: Vim9: crash when getting the types for a legacy function
Bram Moolenaar <Bram@vim.org>
parents: 24033
diff changeset
9561 ga_init2(&ufunc->uf_type_list, sizeof(type_T *), 10);
20532
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9562 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
9563 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
9564 // 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
9565 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
9566 argcount + varargs,
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9567 &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
9568 return;
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9569 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
9570 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
9571 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
9572 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
9573 {
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9574 int i;
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9575
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9576 // 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
9577 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
9578 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
9579 }
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9580 else
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9581 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
9582 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
9583 if (varargs)
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9584 {
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9585 ufunc->uf_func_type->tt_args[argcount] =
24400
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24390
diff changeset
9586 ufunc->uf_va_type == NULL ? &t_list_any : ufunc->uf_va_type;
20532
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9587 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
9588 }
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9589 }
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9590 else
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9591 // 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
9592 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
9593 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
9594 }
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9595
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9596
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9597 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9598 * 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
9599 */
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9600 void
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9601 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
9602 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9603 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
9604 {
22973
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
9605 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
9606 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
9607 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
9608 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
9609 case ISN_LOADENV:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9610 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
9611 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
9612 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
9613 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
9614 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
9615 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
9616 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
9617 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
9618 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
9619 case ISN_STOREB:
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
9620 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
9621 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
9622 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
9623 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
9624 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
9625 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
9626 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9627
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9628 case ISN_SUBSTITUTE:
24492
cca0a1b4e878 patch 8.2.2786: Vim9: memory leak when using :s with expression
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
9629 {
cca0a1b4e878 patch 8.2.2786: Vim9: memory leak when using :s with expression
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
9630 int idx;
cca0a1b4e878 patch 8.2.2786: Vim9: memory leak when using :s with expression
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
9631 isn_T *list = isn->isn_arg.subs.subs_instr;
cca0a1b4e878 patch 8.2.2786: Vim9: memory leak when using :s with expression
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
9632
cca0a1b4e878 patch 8.2.2786: Vim9: memory leak when using :s with expression
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
9633 vim_free(isn->isn_arg.subs.subs_cmd);
cca0a1b4e878 patch 8.2.2786: Vim9: memory leak when using :s with expression
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
9634 for (idx = 0; list[idx].isn_type != ISN_FINISH; ++idx)
cca0a1b4e878 patch 8.2.2786: Vim9: memory leak when using :s with expression
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
9635 delete_instr(list + idx);
cca0a1b4e878 patch 8.2.2786: Vim9: memory leak when using :s with expression
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
9636 vim_free(list);
cca0a1b4e878 patch 8.2.2786: Vim9: memory leak when using :s with expression
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
9637 }
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9638 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9639
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
9640 case ISN_INSTR:
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
9641 {
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
9642 int idx;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
9643 isn_T *list = isn->isn_arg.instr;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
9644
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
9645 for (idx = 0; list[idx].isn_type != ISN_FINISH; ++idx)
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
9646 delete_instr(list + idx);
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
9647 vim_free(list);
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
9648 }
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
9649 break;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
9650
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9651 case ISN_LOADS:
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
9652 case ISN_STORES:
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
9653 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
9654 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9655
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9656 case ISN_UNLET:
20099
058b41f85bcb patch 8.2.0605: Vim9: cannot unlet an environment variable
Bram Moolenaar <Bram@vim.org>
parents: 20091
diff changeset
9657 case ISN_UNLETENV:
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9658 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
9659 break;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9660
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9661 case ISN_STOREOPT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9662 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
9663 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9664
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9665 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
9666 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
9667 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9668
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
9669 case ISN_PUSHJOB:
19562
6b7719b8f9b9 patch 8.2.0338: build failure without the channel feature
Bram Moolenaar <Bram@vim.org>
parents: 19558
diff changeset
9670 #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
9671 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
9672 #endif
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
9673 break;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
9674
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
9675 case ISN_PUSHCHANNEL:
19562
6b7719b8f9b9 patch 8.2.0338: build failure without the channel feature
Bram Moolenaar <Bram@vim.org>
parents: 19558
diff changeset
9676 #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
9677 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
9678 #endif
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
9679 break;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
9680
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9681 case ISN_UCALL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9682 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
9683 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9684
20283
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
9685 case ISN_FUNCREF:
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
9686 {
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
9687 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
9688 + 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
9689 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
9690
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
9691 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
9692 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
9693 }
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
9694 break;
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
9695
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
9696 case ISN_DCALL:
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
9697 {
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
9698 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
9699 + 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
9700
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22369
diff changeset
9701 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
9702 && 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
9703 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
9704 }
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
9705 break;
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
9706
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
9707 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
9708 {
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
9709 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
9710 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
9711
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
9712 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
9713 {
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
9714 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
9715 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
9716 }
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
9717
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
9718 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
9719 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
9720 }
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
9721 break;
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
9722
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
9723 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
9724 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
9725 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
9726 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
9727
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
9728 case ISN_CMDMOD:
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
9729 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
9730 ->cmod_filter_regmatch.regprog);
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
9731 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
9732 break;
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
9733
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
9734 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
9735 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
9736 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
9737 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
9738
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
9739 case ISN_TRY:
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
9740 vim_free(isn->isn_arg.try.try_ref);
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
9741 break;
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
9742
24590
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9743 case ISN_CEXPR_CORE:
24592
ae2eb2c496ed patch 8.2.2835: Vim9: leaking memory in :cexpr
Bram Moolenaar <Bram@vim.org>
parents: 24590
diff changeset
9744 vim_free(isn->isn_arg.cexpr.cexpr_ref->cer_cmdline);
24590
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9745 vim_free(isn->isn_arg.cexpr.cexpr_ref);
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9746 break;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9747
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9748 case ISN_2BOOL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9749 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
9750 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
9751 case ISN_ADDBLOB:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9752 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
9753 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
9754 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
9755 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
9756 case ISN_BLOBAPPEND:
24432
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
9757 case ISN_BLOBINDEX:
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
9758 case ISN_BLOBSLICE:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9759 case ISN_CATCH:
24590
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9760 case ISN_CEXPR_AUCMD:
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
9761 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
9762 case ISN_CHECKNR:
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
9763 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
9764 case ISN_COMPAREANY:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9765 case ISN_COMPAREBLOB:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9766 case ISN_COMPAREBOOL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9767 case ISN_COMPAREDICT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9768 case ISN_COMPAREFLOAT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9769 case ISN_COMPAREFUNC:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9770 case ISN_COMPARELIST:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9771 case ISN_COMPARENR:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9772 case ISN_COMPARESPECIAL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9773 case ISN_COMPARESTRING:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9774 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
9775 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
9776 case ISN_DROP:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9777 case ISN_ECHO:
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
9778 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
9779 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
9780 case ISN_ENDTRY:
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
9781 case ISN_EXECCONCAT:
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
9782 case ISN_EXECUTE:
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
9783 case ISN_FINALLY:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9784 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
9785 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
9786 case ISN_JUMP:
24272
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
9787 case ISN_JUMP_IF_ARG_SET:
22633
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
9788 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
9789 case ISN_LISTINDEX:
21828
af5db9b6d210 patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21826
diff changeset
9790 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
9791 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
9792 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
9793 case ISN_LOADGDICT:
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
9794 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
9795 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
9796 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
9797 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
9798 case ISN_LOADWDICT:
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9799 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
9800 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
9801 case ISN_NEGATENR:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9802 case ISN_NEWDICT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9803 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
9804 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
9805 case ISN_OPFLOAT:
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9806 case ISN_FINISH:
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
9807 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
9808 case ISN_PCALL:
19862
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19860
diff changeset
9809 case ISN_PCALL_END:
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9810 case ISN_PROF_END:
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9811 case ISN_PROF_START:
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
9812 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
9813 case ISN_PUSHF:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9814 case ISN_PUSHNR:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9815 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
9816 case ISN_PUT:
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9817 case ISN_REDIREND:
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9818 case ISN_REDIRSTART:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9819 case ISN_RETURN:
23543
f90e429453fd patch 8.2.2314: Vim9: returning zero takes two instructions
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
9820 case ISN_RETURN_ZERO:
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
9821 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
9822 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
9823 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
9824 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
9825 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
9826 case ISN_STOREOUTER:
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9827 case ISN_STORERANGE:
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
9828 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
9829 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
9830 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
9831 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
9832 case ISN_THROW:
23927
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
9833 case ISN_TRYCONT:
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
9834 case ISN_UNLETINDEX:
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
9835 case ISN_UNLETRANGE:
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
9836 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
9837 // nothing allocated
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9838 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9839 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9840 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9841
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9842 /*
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
9843 * 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
9844 */
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9845 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
9846 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
9847 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9848 int idx;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9849
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9850 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
9851
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9852 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
9853 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9854 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
9855 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
9856 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
9857 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
9858 }
23729
7eef04861034 patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 23725
diff changeset
9859 #ifdef FEAT_PROFILE
7eef04861034 patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 23725
diff changeset
9860 if (dfunc->df_instr_prof != NULL)
7eef04861034 patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 23725
diff changeset
9861 {
7eef04861034 patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 23725
diff changeset
9862 for (idx = 0; idx < dfunc->df_instr_prof_count; ++idx)
7eef04861034 patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 23725
diff changeset
9863 delete_instr(dfunc->df_instr_prof + idx);
7eef04861034 patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 23725
diff changeset
9864 VIM_CLEAR(dfunc->df_instr_prof);
7eef04861034 patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 23725
diff changeset
9865 dfunc->df_instr_prof = NULL;
7eef04861034 patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 23725
diff changeset
9866 }
7eef04861034 patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 23725
diff changeset
9867 #endif
23360
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
9868
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
9869 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
9870 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
9871 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
9872 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
9873 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9874
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9875 /*
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
9876 * 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
9877 * 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
9878 * 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
9879 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9880 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
9881 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
9882 {
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
9883 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
9884 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9885 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
9886 + 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
9887
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
9888 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
9889 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
9890 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
9891 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
9892 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
9893 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
9894 }
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
9895 }
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
9896
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
9897 /*
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
9898 * 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
9899 */
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
9900 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
9901 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
9902 {
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
9903 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
9904 {
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
9905 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
9906 + 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
9907
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
9908 ++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
9909 }
22324
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
9910 }
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
9911
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9912 #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
9913 /*
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9914 * 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
9915 */
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9916 void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9917 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
9918 {
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9919 int idx;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9920
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9921 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
9922 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9923 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
9924
23360
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
9925 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
9926 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
9927 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9928
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9929 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
9930 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9931 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9932
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9933
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9934 #endif // FEAT_EVAL