annotate src/vim9compile.c @ 25057:ffc3e1164652 v8.2.3065

patch 8.2.3065: Vim9: error when sourcing script twice and reusing function Commit: https://github.com/vim/vim/commit/577dc93da9ec78684576bff71328d40f24bd6dd8 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 27 15:35:40 2021 +0200 patch 8.2.3065: Vim9: error when sourcing script twice and reusing function Problem: Vim9: error when sourcing script twice and reusing a function name. Solution: Check if the function is dead. (closes #8463)
author Bram Moolenaar <Bram@vim.org>
date Sun, 27 Jun 2021 15:45:03 +0200
parents 8d660d1cca8d
children 671ded1facd5
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
25004
70f55a30f03c patch 8.2.3039: Vim9: breakpoint at a comment line does not work
Bram Moolenaar <Bram@vim.org>
parents: 24984
diff changeset
177 int ctx_prev_lnum; // line number below previous command, for
70f55a30f03c patch 8.2.3039: Vim9: breakpoint at a comment line does not work
Bram Moolenaar <Bram@vim.org>
parents: 24984
diff changeset
178 // debugging
70f55a30f03c patch 8.2.3039: Vim9: breakpoint at a comment line does not work
Bram Moolenaar <Bram@vim.org>
parents: 24984
diff changeset
179
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
180 compiletype_T ctx_compile_type;
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
181
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 garray_T ctx_locals; // currently visible local variables
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22369
diff changeset
184 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
185 // the function
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
186
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 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
188
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
189 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
190 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
191 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
192
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
193 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
194 // function
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
195 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
196
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 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
198 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
199
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
200 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
201
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
202 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
203 // 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
204 };
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205
23360
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
206 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
207
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 /*
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 * 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
210 * "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
211 * 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
212 * 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
213 */
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
214 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
215 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
216 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 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
218 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
219
19392
5b6f420e7352 patch 8.2.0254: compiler warning for checking size_t to be negative
Bram Moolenaar <Bram@vim.org>
parents: 19388
diff changeset
220 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
221 return FAIL;
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
222
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
223 // 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
224 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
225 {
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
226 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
227 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
228 && 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
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 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
231 {
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
232 *lvar = *lvp;
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
233 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
234 }
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
235 return OK;
20244
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 }
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
238
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
239 // 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
240 if (cctx->ctx_outer != NULL)
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
241 {
23171
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 (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
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 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
245 {
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
246 cctx->ctx_outer_used = TRUE;
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
247 ++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
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 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
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 }
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
252
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
253 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 /*
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
257 * 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
258 * 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
259 * 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
260 * 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
261 * 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
262 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 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
264 arg_exists(
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
265 char_u *name,
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
266 size_t len,
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
267 int *idxp,
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
268 type_T **type,
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
269 int *gen_load_outer,
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
270 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
271 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 int idx;
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
273 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
274
19392
5b6f420e7352 patch 8.2.0254: compiler warning for checking size_t to be negative
Bram Moolenaar <Bram@vim.org>
parents: 19388
diff changeset
275 if (len == 0)
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
276 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 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
278 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 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
280
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
281 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
282 {
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
283 if (idxp != NULL)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
284 {
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
285 // 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
286 // 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
287 *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
288 + STACK_FRAME_SIZE)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
289 + (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
290
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
291 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
292 *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
293 else
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
294 *type = &t_any;
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 return OK;
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 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
299
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
300 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
301 if (va_name != NULL
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
302 && 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
303 {
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
304 if (idxp != NULL)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
305 {
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
306 // 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
307 *idxp = -STACK_FRAME_SIZE - 1;
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
308 *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
309 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
310 return OK;
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
311 }
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 if (cctx->ctx_outer != NULL)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
314 {
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
315 // 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
316 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
317 == OK)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
318 {
23923
be36288235af patch 8.2.2504: Vim9: crash when using an argument from a closure
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
319 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
320 ++*gen_load_outer;
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
321 return OK;
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 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
324
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
325 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 /*
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
329 * 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
330 * 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
331 * "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
332 * 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
333 * 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
334 */
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
335 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
336 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
337 {
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
338 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
339 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
340 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
341 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
342 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
343
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
344 // 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
345 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
346 {
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
347 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
348 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
349 }
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
350 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
351 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
352 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
353 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
354 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
355
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
356 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
357 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
358 // 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
359 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
360
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
361 // 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
362 // 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
363 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
364 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
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 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
367
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
368 // 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
369 // 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
370 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
371 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
372 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
373 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
374 }
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 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
377 }
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
378
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
379 /*
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 23199
diff changeset
380 * 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
381 */
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 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
383 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
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 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
386 }
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
387
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
388 /*
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
389 * 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
390 * "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
391 * 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
392 */
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
393 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
394 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
395 {
22381
6fe9536694ff patch 8.2.1739: Vim9: crash when compiling a manually defined function
Bram Moolenaar <Bram@vim.org>
parents: 22371
diff changeset
396 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
397 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
398 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
399 {
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
400 // 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
401 // defined.
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
402 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
403 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
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 else
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
406 {
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
407 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
408 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
409 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
410
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
411 // 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
412 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
413 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
414 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
415 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
416 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
417 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
418 }
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
419
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
420 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422
19623
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
423 /*
23966
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
424 * 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
425 * imported.
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
426 */
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
427 static int
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
428 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
429 {
24033
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
430 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
431 && (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
432 || 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
433 || 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
434 || 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
435 }
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
436
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
437 /*
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
438 * 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
439 * 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
440 */
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 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
442 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
443 {
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 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
445 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
446
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 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
448 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
449
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
450 // 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
451 // 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
452 // 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
453 // 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
454 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
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 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
457 {
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 // Do not check for an internal function, since it might also be a
24914
1186160ecf57 patch 8.2.2994: various code is not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24903
diff changeset
459 // valid command, such as ":split" versus "split()".
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
460 // 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
461 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
462 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
463 }
f4061617c438 patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents: 24116
diff changeset
464 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
465 }
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
466
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
467 /*
19623
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
468 * 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
469 * 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
470 * 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
471 * 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
472 * 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
473 */
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
474 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
475 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
476 {
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
477 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
478 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
479
24420
e0fa539a9b34 patch 8.2.2750: Vim9: error for using underscore in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24408
diff changeset
480 // 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
481 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
482 return OK;
e0fa539a9b34 patch 8.2.2750: Vim9: error for using underscore in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24408
diff changeset
483
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
484 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
485 {
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
486 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
487 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
488 else
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
489 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
490 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
491 }
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
492
21604
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
493 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
494 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
495 && (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
496 || 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
497 || 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
498 || (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
499 {
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
500 // A local or script-local function can shadow a global function.
25057
ffc3e1164652 patch 8.2.3065: Vim9: error when sourcing script twice and reusing function
Bram Moolenaar <Bram@vim.org>
parents: 25034
diff changeset
501 if (ufunc == NULL || ((ufunc->uf_flags & FC_DEAD) == 0
ffc3e1164652 patch 8.2.3065: Vim9: error when sourcing script twice and reusing function
Bram Moolenaar <Bram@vim.org>
parents: 25034
diff changeset
502 && (!func_is_global(ufunc)
ffc3e1164652 patch 8.2.3065: Vim9: error when sourcing script twice and reusing function
Bram Moolenaar <Bram@vim.org>
parents: 25034
diff changeset
503 || (p[0] == 'g' && p[1] == ':'))))
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
504 {
24033
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
505 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
506 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
507 else
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
508 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
509 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
510 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
511 }
19623
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
512 }
21604
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
513 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
514 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
515 }
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
516
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
517
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 /////////////////////////////////////////////////////////////////////
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 // 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
520
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
521 #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
522 #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
523
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 * 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
526 * 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
527 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 static isn_T *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 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
530 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 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
532 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
534 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
535 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
536 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 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
538 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
539 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
540 ++instr->ga_len;
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 return isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 * 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
547 * "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
548 * 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
549 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 static isn_T *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 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
552 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 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
554
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
555 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
556 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
557 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
558 }
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 * 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
562 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 static isn_T *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 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
565 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 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
568
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 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
570 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 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
573 return NULL;
21473
8bcd1ee2630b patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
574 ((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
575 ++stack->ga_len;
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 return isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 /*
24918
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
581 * Generate an ISN_DEBUG instruction.
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
582 */
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
583 static isn_T *
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
584 generate_instr_debug(cctx_T *cctx)
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
585 {
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
586 isn_T *isn;
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
587 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
588 + cctx->ctx_ufunc->uf_dfunc_idx;
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
589
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
590 if ((isn = generate_instr(cctx, ISN_DEBUG)) == NULL)
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
591 return NULL;
25004
70f55a30f03c patch 8.2.3039: Vim9: breakpoint at a comment line does not work
Bram Moolenaar <Bram@vim.org>
parents: 24984
diff changeset
592 isn->isn_arg.debug.dbg_var_names_len = dfunc->df_var_names.ga_len;
70f55a30f03c patch 8.2.3039: Vim9: breakpoint at a comment line does not work
Bram Moolenaar <Bram@vim.org>
parents: 24984
diff changeset
593 isn->isn_arg.debug.dbg_break_lnum = cctx->ctx_prev_lnum;
24918
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
594 return isn;
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
595 }
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
596
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
597 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 * 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
599 * But only for simple types.
24796
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
600 * When "tolerant" is TRUE convert most types to string, e.g. a List.
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
601 */
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
602 static int
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
603 may_generate_2STRING(int offset, int tolerant, 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
604 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 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
606 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
607 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
608 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
609
4cd173b3d572 patch 8.2.2330: Vim9: crash when using :trow in a not executed block
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
610 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
611 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
612 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
613 {
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
614 // 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
615 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
616
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
617 // 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
618 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
619 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
620 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
621 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
622 break;
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
623
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
624 // 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
625 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
626 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
627 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
628 break;
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
629
24796
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
630 // conversion possible when tolerant
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
631 case VAR_LIST:
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
632 if (tolerant)
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
633 {
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
634 isntype = ISN_2STRING_ANY;
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
635 break;
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
636 }
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
637 // FALLTHROUGH
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
638
21771
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
639 // 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
640 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
641 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
642 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
643 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
644 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
645 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
646 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
647 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
648 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
649 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
650 }
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
651
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 *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
653 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
654 return FAIL;
24796
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
655 isn->isn_arg.tostring.offset = offset;
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
656 isn->isn_arg.tostring.tolerant = tolerant;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 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
663 {
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
664 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
665 && (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
666 || 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
667 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 if (*op == '+')
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
669 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
670 else
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
671 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
672 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
677 static int
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
678 generate_add_instr(
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
679 cctx_T *cctx,
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
680 vartype_T vartype,
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
681 type_T *type1,
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
682 type_T *type2)
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
683 {
23199
59f31d2eb4cf patch 8.2.2145: Vim9: concatenating lists does not adjust type of result
Bram Moolenaar <Bram@vim.org>
parents: 23195
diff changeset
684 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
685 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
686 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
687 : 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
688 : 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
689 #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
690 : 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
691 #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
692 : ISN_OPANY, 1);
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
693
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
694 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
695 && type1->tt_type != VAR_ANY
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
696 && type2->tt_type != VAR_ANY
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
697 && check_number_or_float(
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
698 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
699 return FAIL;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
700
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
701 if (isn != NULL)
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
702 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
703
59f31d2eb4cf patch 8.2.2145: Vim9: concatenating lists does not adjust type of result
Bram Moolenaar <Bram@vim.org>
parents: 23195
diff changeset
704 // 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
705 // 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
706 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
707 && 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
708 && 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
709 (((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
710
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
711 return isn == NULL ? FAIL : OK;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
712 }
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
713
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
714 /*
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
715 * 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
716 * "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
717 * 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
718 */
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
719 static vartype_T
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
720 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
721 {
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
722 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
723 && (type1->tt_type == VAR_NUMBER
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
724 || type1->tt_type == VAR_LIST
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
725 #ifdef FEAT_FLOAT
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
726 || type1->tt_type == VAR_FLOAT
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
727 #endif
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
728 || type1->tt_type == VAR_BLOB))
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
729 return type1->tt_type;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
730 return VAR_ANY;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
731 }
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
732
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 * 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
735 * 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
736 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 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
739 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 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
741 type_T *type1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 type_T *type2;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 vartype_T vartype;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
746 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
747
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
748 // 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
749 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
750 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
751 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
752
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 switch (*op)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 {
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
755 case '+':
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
756 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
757 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 case '-':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 case '*':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 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
763 op) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 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
766 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
767 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 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
769 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
770 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 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
773 if (isn != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 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
775 ? 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
776 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
778 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
779 && 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
780 || (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
781 && 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
782 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
783 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
784 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 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
787 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
788 if (isn != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 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
790 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 // 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
794 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
795 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 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
797
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 // 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
800 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
801 && (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
802 type = &t_float;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 ((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
805 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 return OK;
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
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 /*
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
811 * 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
812 * 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
813 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
814 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
815 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
816 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 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
818
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
819 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
820 type1 = VAR_ANY;
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
821 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
822 type2 = VAR_ANY;
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
823
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 if (type1 == type2)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 switch (type1)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 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
829 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
830 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
831 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
832 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
833 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
834 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
835 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
836 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
837 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
838 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 }
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
840 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
841 || ((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
842 && (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
843 isntype = ISN_COMPAREANY;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
845 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
846 && (isntype == ISN_COMPAREBOOL
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 || isntype == ISN_COMPARESPECIAL
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 || isntype == ISN_COMPARENR
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 || isntype == ISN_COMPAREFLOAT))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
851 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
852 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
853 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
854 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 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
856 || ((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
857 && (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
858 || 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
859 || ((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
860 && 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
861 && (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
862 || 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
863 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
864 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
865 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
866 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
867 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
868 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
869 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
870
21251
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
871 int
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
872 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
873 {
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
874 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
875 return FAIL;
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
876 return OK;
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
877 }
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
878
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
879 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
880 * 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
881 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
882 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
883 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
884 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
885 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
886 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
887 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
888 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
889 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
890
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
891 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
892
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
893 // 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
894 // 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
895 // checking.
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
896 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
897 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
898 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
899 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
900 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 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
903 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
904 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
905 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
906
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 // 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
908 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
909 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 --stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 ((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
912 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 * Generate an ISN_2BOOL instruction.
24796
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
919 * "offset" is the offset in the type stack.
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
920 */
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
921 static int
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
922 generate_2BOOL(cctx_T *cctx, int invert, int offset)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 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
926
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
927 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
928 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
929 return FAIL;
24796
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
930 isn->isn_arg.tobool.invert = invert;
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
931 isn->isn_arg.tobool.offset = offset;
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 // type becomes bool
24796
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
934 ((type_T **)stack->ga_data)[stack->ga_len + offset] = &t_bool;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
939 /*
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
940 * 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
941 */
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
942 static int
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
943 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
944 {
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
945 isn_T *isn;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
946 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
947
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
948 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
949 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
950 return FAIL;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
951
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
952 // type becomes bool
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
953 ((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
954
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
955 return OK;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
956 }
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
957
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 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
959 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
960 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
961 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
962 int offset,
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
963 int argidx)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 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
967
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
968 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
969 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
970 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
971 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
972 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
973 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
974
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
975 // 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
976 ((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
977
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980
23458
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
981 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
982 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
983 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
984 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
985 {
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
986 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
987
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
988 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
989 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
990 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
991 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
992 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
993 }
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
994
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 /*
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
996 * 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
997 * 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
998 */
22898
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22860
diff changeset
999 int
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
1000 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
1001 {
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
1002 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
1003 || 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
1004 || (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
1005 && (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
1006 || 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
1007 && (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
1008 && ((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
1009 == (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
1010 return TRUE;
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
1011 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
1012 && 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
1013 // 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
1014 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
1015 return FALSE;
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
1016 }
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
1017
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
1018 /*
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
1019 * 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
1020 * - "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
1021 * - "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
1022 * - return FAIL.
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
1023 * 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
1024 * generate a TYPECHECK.
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
1025 */
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
1026 int
21265
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21255
diff changeset
1027 need_type(
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21255
diff changeset
1028 type_T *actual,
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21255
diff changeset
1029 type_T *expected,
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21255
diff changeset
1030 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
1031 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
1032 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
1033 int silent,
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
1034 int actual_is_const)
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
1035 {
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
1036 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
1037
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
1038 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
1039 && (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
1040 {
d835f2fdfcfc patch 8.2.1647: Vim9: result of expression with && and || is not a bool
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
1041 // 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
1042 // boolean is OK but requires a conversion.
24796
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
1043 generate_2BOOL(cctx, FALSE, offset);
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
1044 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
1045 }
d835f2fdfcfc patch 8.2.1647: Vim9: result of expression with && and || is not a bool
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
1046
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
1047 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
1048 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
1049 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
1050 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
1051
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
1052 // 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
1053 // 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
1054 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
1055 {
23691
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
1056 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
1057 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
1058 }
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
1059
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
1060 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
1061 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
1062 return FAIL;
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
1063 }
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
1064
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
1065 /*
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
1066 * 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
1067 * 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
1068 */
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
1069 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
1070 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
1071 {
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
1072 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
1073 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
1074
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
1075 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
1076 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
1077 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
1078
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
1079 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
1080 // 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
1081 // 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
1082 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
1083
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
1084 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
1085 }
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
1086
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
1087 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088 * 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
1089 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 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
1092 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 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
1094 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
1095
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1096 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
1097 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
1098 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 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
1100
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
1101 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
1102 // 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
1103 ((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
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 * 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
1109 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 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
1112 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1115 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
1116 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
1117 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 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
1119
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 }
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 * 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
1125 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 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
1128 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1131 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
1132 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
1133 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 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
1135
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 * 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
1142 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 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
1145 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1148 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
1149 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
1150 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 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
1152
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 * Generate an ISN_PUSHS instruction.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 * Consumes "str".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 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
1163 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165
23473
ad83c0ff34c0 patch 8.2.2279: Vim9: memory leak with catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23458
diff changeset
1166 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
1167 {
ad83c0ff34c0 patch 8.2.2279: Vim9: memory leak with catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23458
diff changeset
1168 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
1169 return OK;
ad83c0ff34c0 patch 8.2.2279: Vim9: memory leak with catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23458
diff changeset
1170 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 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
1172 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 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
1174
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 /*
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1179 * 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
1180 * Consumes "channel".
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1181 */
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1182 static int
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1183 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
1184 {
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1185 isn_T *isn;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1186
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1187 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
1188 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
1189 return FAIL;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1190 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
1191
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1192 return OK;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1193 }
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1194
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1195 /*
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1196 * 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
1197 * Consumes "job".
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1198 */
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1199 static int
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1200 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
1201 {
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1202 isn_T *isn;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1203
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1204 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
1205 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
1206 return FAIL;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1207 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
1208
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1209 return OK;
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
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1212 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 * 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
1214 * Consumes "blob".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 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
1218 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1221 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
1222 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
1223 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 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
1225
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 /*
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1230 * 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
1231 * Consumes "name".
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1232 */
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1233 static int
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
1234 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
1235 {
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1236 isn_T *isn;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1237
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1238 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
1239 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
1240 return FAIL;
21473
8bcd1ee2630b patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
1241 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
1242
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1243 return OK;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1244 }
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1245
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1246 /*
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1247 * Generate an ISN_GETITEM instruction with "index".
24984
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
1248 * "with_op" is TRUE for "+=" and other operators, the stack has the current
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
1249 * value below the list with values.
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
1250 */
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
1251 static int
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
1252 generate_GETITEM(cctx_T *cctx, int index, int with_op)
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1253 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1254 isn_T *isn;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1255 garray_T *stack = &cctx->ctx_type_stack;
24984
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
1256 type_T *type = ((type_T **)stack->ga_data)[stack->ga_len
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
1257 - (with_op ? 2 : 1)];
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1258 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
1259
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1260 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
1261
21421
0f0fee4122d3 patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents: 21411
diff changeset
1262 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
1263 {
0f0fee4122d3 patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents: 21411
diff changeset
1264 // 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
1265 emsg(_(e_listreq));
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1266 return FAIL;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1267 }
21421
0f0fee4122d3 patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents: 21411
diff changeset
1268 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
1269 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
1270 return FAIL;
24984
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
1271 isn->isn_arg.getitem.gi_index = index;
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
1272 isn->isn_arg.getitem.gi_with_op = with_op;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1273
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1274 // 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
1275 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
1276 return FAIL;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1277 ((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
1278 ++stack->ga_len;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1279 return OK;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1280 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1281
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1282 /*
20871
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1283 * 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
1284 */
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1285 static int
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1286 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
1287 {
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1288 isn_T *isn;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1289
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1290 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
1291 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
1292 return FAIL;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1293 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
1294 return OK;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1295 }
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1296
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1297 /*
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1298 * 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
1299 */
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1300 static int
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1301 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
1302 {
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1303 isn_T *isn;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1304
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1305 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
1306
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1307 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
1308 return FAIL;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1309 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
1310 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
1311
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1312 return OK;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1313 }
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1314
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
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_STORE instruction.
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_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
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_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
1325 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 if (name != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 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
1328 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1329 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
1330
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 return OK;
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
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 /*
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1335 * Generate an ISN_STOREOUTER instruction.
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1336 */
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1337 static int
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1338 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
1339 {
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1340 isn_T *isn;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1341
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1342 RETURN_OK_IF_SKIP(cctx);
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1343 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
1344 return FAIL;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1345 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
1346 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
1347
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1348 return OK;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1349 }
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1350
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1351 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 * 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
1353 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 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
1356 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1359 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
1360 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
1361 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
1362 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
1363 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
1364
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1368 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 * 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
1370 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 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
1373 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1374 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1375
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1376 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
1377 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
1378 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379 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
1380 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
1381
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1382 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1386 * 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
1387 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389 generate_LOAD(
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390 cctx_T *cctx,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1391 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
1392 int idx,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393 char_u *name,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1394 type_T *type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1396 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1397
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1398 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
1399 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
1400 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1401 if (name != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 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
1403 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 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
1405
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1406 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1407 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1408
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1409 /*
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1410 * Generate an ISN_LOADOUTER instruction
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1411 */
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1412 static int
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1413 generate_LOADOUTER(
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1414 cctx_T *cctx,
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1415 int idx,
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1416 int nesting,
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1417 type_T *type)
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1418 {
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1419 isn_T *isn;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1420
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1421 RETURN_OK_IF_SKIP(cctx);
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1422 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
1423 return FAIL;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1424 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
1425 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
1426
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1427 return OK;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1428 }
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1429
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1430 /*
19960
3c11b9f6fa03 patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1431 * 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
1432 */
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1433 static int
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1434 generate_LOADV(
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1435 cctx_T *cctx,
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1436 char_u *name,
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1437 int error)
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1438 {
19960
3c11b9f6fa03 patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1439 int di_flags;
3c11b9f6fa03 patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1440 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
1441 type_T *type;
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1442
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1443 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
1444 if (vidx < 0)
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1445 {
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1446 if (error)
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
1447 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
1448 return FAIL;
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1449 }
21443
66386ca8a69f patch 8.2.1272: Vim9: type not checked if declaration also assigns value
Bram Moolenaar <Bram@vim.org>
parents: 21441
diff changeset
1450 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
1451
3c11b9f6fa03 patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1452 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
1453 }
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1454
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1455 /*
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1456 * Generate an ISN_UNLET instruction.
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1457 */
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1458 static int
20099
058b41f85bcb patch 8.2.0605: Vim9: cannot unlet an environment variable
Bram Moolenaar <Bram@vim.org>
parents: 20091
diff changeset
1459 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
1460 {
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1461 isn_T *isn;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1462
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1463 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
1464 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
1465 return FAIL;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1466 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
1467 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
1468
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1469 return OK;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1470 }
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1471
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1472 /*
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1473 * 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
1474 */
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1475 static int
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1476 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
1477 {
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1478 isn_T *isn;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1479
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1480 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
1481 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
1482 return FAIL;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1483 return OK;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1484 }
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1485
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1486 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1487 * 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
1488 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1489 static int
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1490 generate_OLDSCRIPT(
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1491 cctx_T *cctx,
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1492 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
1493 char_u *name,
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1494 int sid,
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1495 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
1496 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1497 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1498
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1499 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
1500 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
1501 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
1502 else
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1503 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
1504 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
1505 return FAIL;
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1506 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
1507 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
1508
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_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
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
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1516 generate_VIM9SCRIPT(
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1517 cctx_T *cctx,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1518 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
1519 int sid,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1520 int idx,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521 type_T *type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1523 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
1524 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
1525 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
1526
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1527 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
1528 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
1529 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
1530 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1531 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
1532 if (isn == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1533 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
1534
e8eb4fd44902 patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents: 23318
diff changeset
1535 // 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
1536 // 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
1537 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
1538 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
1539 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
1540 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
1541 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
1542 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
1543 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
1544 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
1545 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1546 }
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 * 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
1550 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 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
1553 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555 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
1556 type_T *type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1557 type_T *member;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1559 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
1560 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
1561 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562 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
1563
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
1564 // 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
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, 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
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_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
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 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 -= 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 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
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_NEWDICT 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
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1589 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
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 type_T *type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1594 type_T *member;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1595
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1596 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
1597 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
1598 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1599 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
1600
22021
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1601 if (count == 0)
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1602 member = &t_void;
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1603 else
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1604 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
1605 ((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
1606 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
1607 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
1608
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1609 // 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
1610 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
1611
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1612 // 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
1613 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
1614 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1615 ((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
1616 ++stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1617
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1618 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1619 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1620
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1621 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1622 * 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
1623 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1624 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
1625 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
1626 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1627 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1628 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
1629
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1630 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
1631 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
1632 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
1633 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
1634 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
1635
24158
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
1636 // 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
1637 // the nested context, including this one.
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1638 if (ufunc->uf_flags & FC_CLOSURE)
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1639 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
1640
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1641 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
1642 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
1643 ((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
1644 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
1645 ++stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1646
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1647 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1648 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1649
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650 /*
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1651 * 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
1652 * "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
1653 * consumed.
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1654 */
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1655 static int
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1656 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
1657 {
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1658 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
1659
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1660 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
1661 {
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1662 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
1663 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
1664 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
1665 }
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1666 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
1667 {
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1668 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
1669 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
1670 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
1671 }
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1672 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
1673 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
1674
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1675 return OK;
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1676 }
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1677
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1678 /*
22973
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1679 * 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
1680 */
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1681 static int
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1682 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
1683 {
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1684 isn_T *isn;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1685
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1686 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
1687 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
1688 return FAIL;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1689 if (len > 0)
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1690 {
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1691 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
1692 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
1693 return FAIL;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1694 }
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1695 return OK;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1696 }
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1697
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
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 * 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
1700 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1701 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1702 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
1703 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1704 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1705 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
1706
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1707 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
1708 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
1709 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1710 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
1711 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
1712
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1713 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
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 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1718
24272
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1719 /*
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1720 * 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
1721 */
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1722 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
1723 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
1724 {
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1725 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
1726
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1727 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
1728 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
1729 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
1730 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
1731 // 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
1732 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
1733 }
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
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 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1736 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
1737 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1738 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1739 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
1740
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1741 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
1742 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
1743 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1744 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
1745
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1746 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
1747 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1748 // 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
1749 ((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
1750 ++stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1751
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1752 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1753 }
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
1754 /*
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1755 * 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
1756 */
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1757 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
1758 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
1759 {
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1760 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
1761
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1762 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
1763 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
1764 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
1765 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
1766 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
1767
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1768 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
1769 }
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1770
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1771
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1772 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1773 * 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
1774 * "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
1775 * 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
1776 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1777 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
1778 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
1779 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1780 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1781 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
1782 int argoff;
22671
ad54acb1bf2c patch 8.2.1884: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents: 22667
diff changeset
1783 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
1784 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
1785
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1786 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
1787 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
1788 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
1789 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1790
21232
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
1791 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
1792 {
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
1793 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
1794 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
1795 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
1796 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
1797 }
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
1798
22663
0f90c15a4a28 patch 8.2.1880: Vim9: asan complains about adding zero to NULL
Bram Moolenaar <Bram@vim.org>
parents: 22661
diff changeset
1799 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
1800 {
0f90c15a4a28 patch 8.2.1880: Vim9: asan complains about adding zero to NULL
Bram Moolenaar <Bram@vim.org>
parents: 22661
diff changeset
1801 // 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
1802 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
1803 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
1804 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
1805 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
1806 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
1807 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
1808 }
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22639
diff changeset
1809
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1810 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
1811 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1812 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
1813 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
1814
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22639
diff changeset
1815 // 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
1816 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
1817 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
1818 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1819 ((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
1820 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
1821 ++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
1822
23565
34aa2907082a patch 8.2.2325: Vim9: crash if map() changes the item type
Bram Moolenaar <Bram@vim.org>
parents: 23561
diff changeset
1823 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
1824 && 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
1825 // 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
1826 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
1827
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1828 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1829 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1830
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1831 /*
22633
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1832 * 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
1833 * 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
1834 */
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1835 static int
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1836 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
1837 {
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1838 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
1839 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
1840 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
1841 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
1842
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1843 // 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
1844 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
1845 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
1846 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
1847 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
1848 return FAIL;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1849
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1850 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
1851 return FAIL;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1852
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1853 --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
1854 return OK;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1855 }
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1856
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1857 /*
22637
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1858 * 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
1859 * 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
1860 */
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1861 static int
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1862 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
1863 {
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1864 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
1865 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
1866
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1867 // 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
1868 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
1869 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
1870 return FAIL;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1871
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1872 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
1873 return FAIL;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1874
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1875 --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
1876 return OK;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1877 }
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1878
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1879 /*
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1880 * 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
1881 * "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
1882 */
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1883 int
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
1884 func_needs_compiling(ufunc_T *ufunc, compiletype_T compile_type)
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1885 {
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1886 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
1887 {
24404
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
1888 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
1889 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
1890
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1891 case UF_COMPILED:
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1892 {
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1893 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
1894 + ufunc->uf_dfunc_idx;
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1895
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
1896 switch (compile_type)
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
1897 {
24897
80edcb27d19a patch 8.2.2986: build failure without the profile feature
Bram Moolenaar <Bram@vim.org>
parents: 24895
diff changeset
1898 case CT_PROFILE:
80edcb27d19a patch 8.2.2986: build failure without the profile feature
Bram Moolenaar <Bram@vim.org>
parents: 24895
diff changeset
1899 #ifdef FEAT_PROFILE
80edcb27d19a patch 8.2.2986: build failure without the profile feature
Bram Moolenaar <Bram@vim.org>
parents: 24895
diff changeset
1900 return dfunc->df_instr_prof == NULL;
80edcb27d19a patch 8.2.2986: build failure without the profile feature
Bram Moolenaar <Bram@vim.org>
parents: 24895
diff changeset
1901 #endif
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
1902 case CT_NONE:
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
1903 return dfunc->df_instr == NULL;
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
1904 case CT_DEBUG:
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
1905 return dfunc->df_instr_debug == NULL;
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
1906 }
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
1907 }
24404
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
1908
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
1909 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
1910 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
1911 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
1912 break;
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
1913 }
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
1914 return FALSE;
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1915 }
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1916
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1917 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1918 * 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
1919 * 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
1920 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1921 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
1922 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
1923 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1924 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1925 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
1926 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
1927 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
1928
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1929 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
1930 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
1931 {
22318
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22292
diff changeset
1932 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
1933 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1934 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1935 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
1936 {
22318
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22292
diff changeset
1937 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
1938 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1939 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1940
24404
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
1941 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
1942 && 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
1943 {
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1944 int i;
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1945
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1946 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
1947 {
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1948 type_T *expected;
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1949 type_T *actual;
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1950
24272
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1951 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
1952 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
1953 && 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
1954 {
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1955 // 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
1956 continue;
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1957 }
19944
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1958 if (i < regular_args)
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1959 {
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1960 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
1961 continue;
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1962 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
1963 }
24400
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24390
diff changeset
1964 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
1965 || 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
1966 // 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
1967 expected = &t_any;
19944
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1968 else
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1969 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
1970 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
1971 TRUE, FALSE) == FAIL)
19944
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1972 {
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1973 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
1974 return FAIL;
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1975 }
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1976 }
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
1977 if (func_needs_compiling(ufunc, COMPILE_TYPE(ufunc))
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1978 && compile_def_function(ufunc, ufunc->uf_ret_type == NULL,
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
1979 COMPILE_TYPE(ufunc), NULL) == FAIL)
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1980 return FAIL;
19944
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1981 }
24854
c9ccb1976049 patch 8.2.2965: Vim9: crash when calling function that failed to compile
Bram Moolenaar <Bram@vim.org>
parents: 24852
diff changeset
1982 if (ufunc->uf_def_status == UF_COMPILE_ERROR)
c9ccb1976049 patch 8.2.2965: Vim9: crash when calling function that failed to compile
Bram Moolenaar <Bram@vim.org>
parents: 24852
diff changeset
1983 {
c9ccb1976049 patch 8.2.2965: Vim9: crash when calling function that failed to compile
Bram Moolenaar <Bram@vim.org>
parents: 24852
diff changeset
1984 emsg_funcname(_(e_call_to_function_that_failed_to_compile_str),
c9ccb1976049 patch 8.2.2965: Vim9: crash when calling function that failed to compile
Bram Moolenaar <Bram@vim.org>
parents: 24852
diff changeset
1985 ufunc->uf_name);
c9ccb1976049 patch 8.2.2965: Vim9: crash when calling function that failed to compile
Bram Moolenaar <Bram@vim.org>
parents: 24852
diff changeset
1986 return FAIL;
c9ccb1976049 patch 8.2.2965: Vim9: crash when calling function that failed to compile
Bram Moolenaar <Bram@vim.org>
parents: 24852
diff changeset
1987 }
19944
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1988
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1989 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
1990 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
1991 : 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
1992 return FAIL;
22326
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
1993 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
1994 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1995 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
1996 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
1997 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1998 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1999 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2000 // 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
2001 // 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
2002 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
2003 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
2004 }
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 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
2007 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
2008 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2009 // add return value
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2010 ((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
2011 ++stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2012
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2013 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2014 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2015
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2016 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2017 * 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
2018 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2019 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2020 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
2021 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2022 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2023 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
2024
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
2025 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
2026 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
2027 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2028 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
2029 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
2030
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2031 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
2032 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
2033 return FAIL;
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
2034 // add return value
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
2035 ((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
2036 ++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
2037
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2038 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2039 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2040
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2041 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2042 * 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
2043 * "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
2044 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2045 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
2046 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
2047 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
2048 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
2049 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
2050 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
2051 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
2052 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2053 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2054 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
2055 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
2056
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
2057 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
2058
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
2059 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
2060 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
2061 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
2062 {
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
2063 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
2064 {
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
2065 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
2066
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
2067 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
2068 {
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
2069 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
2070 return FAIL;
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
2071 }
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
2072 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
2073 {
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
2074 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
2075 return FAIL;
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
2076 }
22816
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2077 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
2078 {
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2079 int i;
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2080
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2081 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
2082 {
24402
009a540f16a6 patch 8.2.2741: Vim9: Partial call does not check right arguments
Bram Moolenaar <Bram@vim.org>
parents: 24400
diff changeset
2083 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
2084 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
2085 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
2086 type_T *expected;
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2087
23527
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23525
diff changeset
2088 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
2089 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
2090 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
2091 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
2092 && 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
2093 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
2094 else
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2095 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
2096 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
2097 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
2098 {
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2099 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
2100 return FAIL;
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2101 }
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2102 }
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2103 }
20281
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
2104 }
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
2105 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
2106 }
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
2107 else
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
2108 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2109 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
2110 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
2111 }
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
2112
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2113 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
2114 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2115 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
2116 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
2117
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2118 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
2119
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2120 // 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
2121 ((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
2122
19862
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19860
diff changeset
2123 // 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
2124 // the return value.
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19860
diff changeset
2125 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
2126 return FAIL;
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19860
diff changeset
2127
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2128 return OK;
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
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2131 /*
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
2132 * 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
2133 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2134 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
2135 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
2136 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2137 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2138 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
2139 type_T *type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2140
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
2141 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
2142 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
2143 return FAIL;
20830
9064044fd4f6 patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
2144 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
2145
19461
08ef11a81daa patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
2146 // 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
2147 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
2148 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
2149 {
08ef11a81daa patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
2150 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
2151 return FAIL;
08ef11a81daa patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
2152 }
08ef11a81daa patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
2153 // 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
2154 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
2155 {
647ff61c0bcd patch 8.2.2323: Vim9: error when inferring type from empty dict/list
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2156 ((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
2157 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
2158 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2159
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2160 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2161 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2162
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2163 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2164 * 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
2165 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2166 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2167 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
2168 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2169 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2170
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
2171 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
2172 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
2173 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2174 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
2175 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
2176
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2177 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2178 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2179
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2180 /*
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
2181 * 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
2182 */
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2183 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
2184 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
2185 {
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2186 isn_T *isn;
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2187
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
2188 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
2189 return FAIL;
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2190 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
2191
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2192 return OK;
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2193 }
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2194
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
2195 /*
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
2196 * 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
2197 */
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
2198 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
2199 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
2200 {
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
2201 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
2202
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
2203 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
2204 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
2205 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
2206 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
2207 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
2208 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
2209 }
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
2210
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2211 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2212 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
2213 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2214 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2215
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
2216 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
2217 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
2218 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2219 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
2220 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2221 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2222
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2223 static int
24645
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
2224 generate_LEGACY_EVAL(cctx_T *cctx, char_u *line)
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
2225 {
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
2226 isn_T *isn;
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
2227 garray_T *stack = &cctx->ctx_type_stack;
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
2228
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
2229 RETURN_OK_IF_SKIP(cctx);
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
2230 if ((isn = generate_instr(cctx, ISN_LEGACY_EVAL)) == NULL)
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
2231 return FAIL;
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
2232 isn->isn_arg.string = vim_strsave(line);
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
2233
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
2234 if (ga_grow(stack, 1) == FAIL)
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
2235 return FAIL;
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
2236 ((type_T **)stack->ga_data)[stack->ga_len] = &t_any;
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
2237 ++stack->ga_len;
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
2238
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
2239 return OK;
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
2240 }
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
2241
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
2242 static int
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2243 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
2244 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2245 isn_T *isn;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2246
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2247 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
2248 return FAIL;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2249 isn->isn_arg.number = count;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2250 return OK;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2251 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2252
23156
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2253 /*
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2254 * 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
2255 */
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2256 static int
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2257 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
2258 {
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2259 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
2260 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
2261
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2262 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
2263 return FAIL;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2264 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
2265
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2266 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
2267 return FAIL;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2268 ((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
2269 ++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
2270 return OK;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2271 }
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2272
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2273 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
2274 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
2275 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2276 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
2277
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2278 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
2279 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
2280 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
2281 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
2282 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
2283 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
2284 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2285
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2286 /*
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
2287 * 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
2288 */
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2289 static int
22699
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 22697
diff changeset
2290 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
2291 {
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2292 isn_T *isn;
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2293
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
2294 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
2295 {
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
2296 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
2297
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
2298 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
2299 return FAIL;
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
2300 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
2301 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
2302 return FAIL;
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
2303 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
2304 // 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
2305 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
2306 }
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
2307
22691
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2308 return OK;
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2309 }
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2310
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2311 static int
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
2312 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
2313 {
23100
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23088
diff changeset
2314 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
2315 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
2316 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
2317 return OK;
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2318 }
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2319
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
2320 static int
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
2321 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
2322 {
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2323 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
2324
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2325 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
2326 && ((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
2327 == ISN_CMDMOD)
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2328 {
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
2329 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
2330 return TRUE;
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
2331 }
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
2332 return FALSE;
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2333 }
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2334
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2335 /*
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2336 * 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
2337 * 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
2338 */
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2339 static int
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2340 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
2341 {
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2342 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
2343 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
2344
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
2345 while (idx > 0)
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
2346 {
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
2347 if (cctx->ctx_has_cmdmod && ((isn_T *)instr->ga_data)[idx - 1]
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2348 .isn_type == ISN_CMDMOD)
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
2349 {
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
2350 --idx;
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
2351 continue;
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
2352 }
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2353 #ifdef FEAT_PROFILE
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
2354 if (((isn_T *)instr->ga_data)[idx - 1].isn_type == ISN_PROF_START)
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
2355 {
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
2356 --idx;
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
2357 continue;
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
2358 }
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2359 #endif
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
2360 if (((isn_T *)instr->ga_data)[idx - 1].isn_type == ISN_DEBUG)
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
2361 {
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
2362 --idx;
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
2363 continue;
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
2364 }
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
2365 break;
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
2366 }
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2367 return idx;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2368 }
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2369
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
2370 #ifdef FEAT_PROFILE
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
2371 static void
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
2372 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
2373 {
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
2374 if (cctx->ctx_compile_type == CT_PROFILE && prof_lnum >= 0)
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
2375 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
2376 }
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
2377 #endif
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
2378
22691
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2379 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2380 * 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
2381 * 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
2382 */
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2383 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
2384 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
2385 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
2386 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
2387 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
2388 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
2389 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
2390 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2391 lvar_T *lvar;
24918
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
2392 dfunc_T *dfunc;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2393
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2394 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
2395 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2396 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
2397 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2398 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2399
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2400 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
2401 return NULL;
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2402 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
2403 CLEAR_POINTER(lvar);
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2404
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2405 // 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
2406 // 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
2407 // 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
2408 // entries. This is less efficient, but memory is cheap these days.
24918
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
2409 dfunc = ((dfunc_T *)def_functions.ga_data) + cctx->ctx_ufunc->uf_dfunc_idx;
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
2410 lvar->lv_idx = dfunc->df_var_names.ga_len;
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2411
20830
9064044fd4f6 patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
2412 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
2413 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
2414 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
2415
24918
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
2416 // Remember the name for debugging.
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
2417 if (ga_grow(&dfunc->df_var_names, 1) == FAIL)
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
2418 return NULL;
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
2419 ((char_u **)dfunc->df_var_names.ga_data)[lvar->lv_idx] =
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
2420 vim_strsave(lvar->lv_name);
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
2421 ++dfunc->df_var_names.ga_len;
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
2422
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2423 return lvar;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2424 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2425
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2426 /*
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2427 * 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
2428 */
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2429 static void
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2430 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
2431 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2432 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
2433 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2434 int idx;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2435 lvar_T *lvar;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2436
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2437 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
2438 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2439 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
2440 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
2441 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2442 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2443 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
2444 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2445
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2446 /*
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2447 * 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
2448 */
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2449 static void
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2450 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
2451 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2452 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
2453 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
2454 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2455
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2456 /*
23578
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2457 * 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
2458 * 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
2459 * 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
2460 */
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2461 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
2462 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
2463 {
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2464 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
2465 || (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
2466 && 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
2467 {
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2468 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
2469 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
2470 }
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2471 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
2472 }
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2473
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2474 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2475 * 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
2476 * 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
2477 * 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
2478 * 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
2479 * 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
2480 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2481 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
2482 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
2483 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2484 hashtab_T *ht;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2485 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
2486 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
2487 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
2488 int idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2489
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2490 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
2491 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
2492 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
2493 {
22598
c7ef64b85e9b patch 8.2.1847: Vim9: using negative value for unsigned type
Bram Moolenaar <Bram@vim.org>
parents: 22596
diff changeset
2494 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
2495
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2496 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
2497 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
2498 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
2499 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
2500 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
2501 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
2502 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
2503 }
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2504
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2505 // 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
2506 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
2507 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
2508 if (di == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2509 return -2;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2510
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2511 // 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
2512 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
2513 {
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2514 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
2515 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
2516 {
23578
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2517 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
2518 return -2;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2519 return idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2520 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2521 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2522 return -1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2523 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2524
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2525 /*
20840
0600ab7b9f09 patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2526 * 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
2527 * NULL.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2528 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2529 imported_T *
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
2530 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
2531 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2532 int idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2533
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2534 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
2535 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2536 if (cctx != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2537 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
2538 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2539 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
2540 + idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2541
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
2542 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
2543 : 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
2544 && 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
2545 return import;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2546 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2547
21699
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2548 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
2549 }
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2550
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2551 imported_T *
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2552 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
2553 {
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2554 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
2555 int idx;
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2556
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2557 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
2558 return NULL;
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2559 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
2560 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
2561 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2562 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
2563
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
2564 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
2565 : 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
2566 && 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
2567 return import;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2568 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2569 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2570 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2571
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2572 /*
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2573 * 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
2574 */
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2575 static void
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2576 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
2577 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2578 int idx;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2579
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2580 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
2581 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2582 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
2583
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2584 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
2585 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2586 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
2587 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2588
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2589 /*
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2590 * 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
2591 * 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
2592 * 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
2593 */
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
2594 char_u *
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
2595 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
2596 {
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2597 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
2598
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2599 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
2600 {
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2601 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
2602 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
2603
21767
9529a2367d3e patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents: 21763
diff changeset
2604 // 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
2605 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
2606 {
9529a2367d3e patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents: 21763
diff changeset
2607 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
2608 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
2609 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
2610 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
2611 return p;
9529a2367d3e patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents: 21763
diff changeset
2612 }
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2613 }
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2614 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
2615 }
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2616
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2617 /*
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2618 * 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
2619 * 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
2620 * 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
2621 * 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
2622 */
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2623 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
2624 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
2625 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2626 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
2627
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2628 *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
2629 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
2630 {
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
2631 *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
2632 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
2633 return *nextp;
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2634 }
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2635 return p;
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2636 }
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2637
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2638 /*
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2639 * 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
2640 * 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
2641 * 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
2642 */
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
2643 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
2644 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
2645 {
20059
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20055
diff changeset
2646 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
2647
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2648 do
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2649 {
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2650 ++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
2651 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
2652 {
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20055
diff changeset
2653 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
2654 break;
20059
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20055
diff changeset
2655 }
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2656 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
2657 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
2658 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
2659 } 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
2660 || (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
2661 return line;
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2662 }
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2663
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2664 /*
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
2665 * 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
2666 * 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
2667 * 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
2668 * 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
2669 */
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2670 static int
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
2671 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
2672 {
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
2673 *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
2674 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
2675 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
2676 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
2677 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2678 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
2679
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2680 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
2681 return FAIL;
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2682 *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
2683 }
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2684 return OK;
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2685 }
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2686
21248
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2687 /*
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2688 * 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
2689 */
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2690 static int
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2691 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
2692 {
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2693 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
2694 {
23122
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23114
diff changeset
2695 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
2696 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
2697 return FAIL;
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2698 }
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2699 return OK;
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2700 }
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2701
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2702
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2703 // 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
2704 // 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
2705 // 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
2706 // 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
2707 // 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
2708 // 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
2709 #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
2710 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
2711 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
2712 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
2713 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
2714 // 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
2715 } 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
2716
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
2717 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
2718 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
2719 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
2720
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2721 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2722 * 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
2723 * "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
2724 * 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
2725 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2726 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
2727 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
2728 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2729 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
2730 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2731 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
2732 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2733 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
2734 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2735 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
2736 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
2737 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2738 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
2739 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
2740 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2741 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
2742 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
2743 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2744 #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
2745 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
2746 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
2747 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2748 #endif
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2749 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
2750 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
2751 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
2752 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2753 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
2754 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
2755 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
2756 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2757 default:
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2758 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
2759 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
2760 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
2761 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2762 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
2763 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2764 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
2765 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2766
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2767 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2768 * 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
2769 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2770 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
2771 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
2772 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2773 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
2774 int ret = OK;
20332
a407e243c55c patch 8.2.0721: Vim9: leaking memory when skipping
Bram Moolenaar <Bram@vim.org>
parents: 20328
diff changeset
2775 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
2776
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
2777 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
2778 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
2779 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
2780 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
2781 ppconst->pp_used = 0;
20332
a407e243c55c patch 8.2.0721: Vim9: leaking memory when skipping
Bram Moolenaar <Bram@vim.org>
parents: 20328
diff changeset
2782 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
2783 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
2784 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2785
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2786 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2787 * 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
2788 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2789 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
2790 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
2791 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2792 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
2793
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2794 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
2795 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
2796 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
2797 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2798
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2799 /*
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 * 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
2801 * 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
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 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
2804 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
2805 {
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 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
2807 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
2808 vartype_T vartype;
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2809 type_T *idxtype;
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2810
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2811 // 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
2812 // 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
2813 // 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
2814 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
2815 - (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
2816 vartype = (*typep)->tt_type;
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2817 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
2818 // 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
2819 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
2820 vartype = VAR_DICT;
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2821 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
2822 {
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2823 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
2824 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
2825 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
2826 {
24602
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2827 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
2828 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
2829 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
2830 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
2831 }
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
2832 }
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
2833
24602
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2834 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
2835 {
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
2836 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
2837 {
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
2838 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
2839 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
2840 }
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
2841 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
2842 {
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
2843 *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
2844 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
2845 // 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
2846 *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
2847 }
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
2848 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
2849 {
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
2850 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
2851 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
2852 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
2853 *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
2854 }
24796
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
2855 if (may_generate_2STRING(-1, FALSE, cctx) == 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
2856 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
2857 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
2858 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
2859 }
24602
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2860 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
2861 {
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
2862 *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
2863 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
2864 ? 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
2865 : 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
2866 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
2867 }
24602
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2868 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
2869 {
24432
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2870 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
2871 {
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2872 *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
2873 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
2874 return FAIL;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2875 }
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2876 else
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2877 {
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2878 *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
2879 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
2880 return FAIL;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2881 }
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
2882 }
24602
033b43570140 patch 8.2.2840: Vim9: member operation not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
2883 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
2884 {
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
2885 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
2886 {
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
2887 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
2888 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
2889 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
2890 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
2891 }
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
2892 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
2893 {
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
2894 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
2895 {
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
2896 *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
2897 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
2898 // 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
2899 *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
2900 }
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
2901 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
2902 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
2903 == 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
2904 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
2905 }
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
2906 }
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
2907 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
2908 {
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
2909 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
2910 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
2911 }
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
2912 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
2913 }
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
2914
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
2915 /*
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2916 * 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
2917 * leading "s:".
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2918 * 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
2919 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2920 static int
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2921 compile_load_scriptvar(
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2922 cctx_T *cctx,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2923 char_u *name, // variable NUL terminated
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2924 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
2925 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
2926 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
2927 {
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2928 scriptitem_T *si;
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2929 int idx;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2930 imported_T *import;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2931
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2932 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
2933 return FAIL;
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2934 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
2935 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
2936 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
2937 {
19451
b26e96f7c12f patch 8.2.0283: Vim9: failing to load script var not tested
Bram Moolenaar <Bram@vim.org>
parents: 19437
diff changeset
2938 // 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
2939 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
2940 &t_any);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2941 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2942 if (idx >= 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2943 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2944 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
2945
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
2946 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
2947 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
2948 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2949 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2950
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
2951 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
2952 if (import != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2953 {
23364
17a0e32eefd4 patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents: 23362
diff changeset
2954 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
2955 {
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2956 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
2957 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
2958 int cc;
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2959 ufunc_T *ufunc;
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2960 type_T *type;
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2961
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2962 // 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
2963 if (*p != '.')
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2964 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2965 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
2966 return FAIL;
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2967 }
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2968 ++p;
19818
c1c88b333481 patch 8.2.0465: Vim9: dead code and wrong return type
Bram Moolenaar <Bram@vim.org>
parents: 19785
diff changeset
2969 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
2970 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2971 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
2972 return FAIL;
c1c88b333481 patch 8.2.0465: Vim9: dead code and wrong return type
Bram Moolenaar <Bram@vim.org>
parents: 19785
diff changeset
2973 }
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2974
21146
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2975 // 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
2976 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
2977 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
2978 ++p;
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2979 cc = *p;
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2980 *p = NUL;
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2981
24116
a028cb6898a2 patch 8.2.2599: build failure
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
2982 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
2983 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
2984 *p = cc;
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2985 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
2986 *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
2987
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2988 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
2989 {
bcfff560e089 patch 8.2.2682: Vim9: cannot find Name.Func from "import * as Name"
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
2990 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
2991 {
bcfff560e089 patch 8.2.2682: Vim9: cannot find Name.Func from "import * as Name"
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
2992 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
2993 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
2994 }
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2995 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
2996 }
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2997
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2998 generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2999 import->imp_sid,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
3000 idx,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
3001 type);
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
3002 }
21473
8bcd1ee2630b patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
3003 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
3004 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
3005 else
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
3006 generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
3007 import->imp_sid,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
3008 import->imp_var_vals_idx,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
3009 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
3010 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3011 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3012
19530
48e71f948360 patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
3013 if (error)
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
3014 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
3015 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3016 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3017
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
3018 static int
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
3019 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
3020 {
20189
63cc54100ae4 patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents: 20174
diff changeset
3021 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
3022
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
3023 if (ufunc == NULL)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
3024 return FAIL;
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
3025
21469
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
3026 // Need to compile any default values to get the argument types.
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
3027 if (func_needs_compiling(ufunc, COMPILE_TYPE(ufunc))
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
3028 && compile_def_function(ufunc, TRUE, COMPILE_TYPE(ufunc), NULL)
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
3029 == FAIL)
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
3030 return FAIL;
21473
8bcd1ee2630b patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
3031 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
3032 }
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
3033
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3034 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3035 * 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
3036 * "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
3037 * "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
3038 * 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
3039 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3040 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
3041 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
3042 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
3043 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
3044 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
3045 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
3046 int error)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3047 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3048 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
3049 char_u *name = NULL;
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
3050 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
3051 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
3052 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
3053
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3054 if (*(*arg + 1) == ':')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3055 {
19822
fc3cdc819d80 patch 8.2.0467: Vim9: some errors are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19818
diff changeset
3056 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
3057 {
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
3058 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
3059
24390
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3060 // 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
3061 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
3062 {
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
3063 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
3064 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
3065 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
3066 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
3067 default:
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
3068 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
3069 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
3070 }
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
3071 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
3072 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
3073 res = OK;
19822
fc3cdc819d80 patch 8.2.0467: Vim9: some errors are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19818
diff changeset
3074 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3075 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3076 {
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
3077 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
3078
24390
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3079 // 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
3080 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
3081 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
3082 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
3083
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
3084 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
3085 {
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
3086 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
3087 break;
24390
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3088 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
3089 && 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
3090 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
3091 else
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3092 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
3093 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
3094 break;
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3095 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
3096 {
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3097 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
3098 && 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
3099 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
3100 else
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3101 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
3102 }
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3103 else
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3104 {
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3105 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
3106 vim_free(name);
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3107 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
3108 if (name == NULL)
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3109 return FAIL;
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3110 }
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3111 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
3112 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
3113 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
3114 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
3115 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
3116 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
3117 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
3118 }
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
3119 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
3120 {
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
3121 // 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
3122 // 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
3123 // 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
3124 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
3125 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3126 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3127 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3128 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3129 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3130 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
3131 int idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3132 int gen_load = FALSE;
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
3133 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
3134
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3135 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
3136 if (name == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3137 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3138
24874
14b0b35d8488 patch 8.2.2975: Vim9: can only use an autoload function name as a string
Bram Moolenaar <Bram@vim.org>
parents: 24854
diff changeset
3139 if (vim_strchr(name, AUTOLOAD_CHAR) != NULL)
14b0b35d8488 patch 8.2.2975: Vim9: can only use an autoload function name as a string
Bram Moolenaar <Bram@vim.org>
parents: 24854
diff changeset
3140 {
14b0b35d8488 patch 8.2.2975: Vim9: can only use an autoload function name as a string
Bram Moolenaar <Bram@vim.org>
parents: 24854
diff changeset
3141 script_autoload(name, FALSE);
14b0b35d8488 patch 8.2.2975: Vim9: can only use an autoload function name as a string
Bram Moolenaar <Bram@vim.org>
parents: 24854
diff changeset
3142 res = generate_LOAD(cctx, ISN_LOADAUTO, 0, name, &t_any);
14b0b35d8488 patch 8.2.2975: Vim9: can only use an autoload function name as a string
Bram Moolenaar <Bram@vim.org>
parents: 24854
diff changeset
3143 }
14b0b35d8488 patch 8.2.2975: Vim9: can only use an autoload function name as a string
Bram Moolenaar <Bram@vim.org>
parents: 24854
diff changeset
3144 else if (arg_exists(*arg, len, &idx, &type, &gen_load_outer, cctx)
14b0b35d8488 patch 8.2.2975: Vim9: can only use an autoload function name as a string
Bram Moolenaar <Bram@vim.org>
parents: 24854
diff changeset
3145 == OK)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3146 {
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
3147 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
3148 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
3149 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3150 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3151 {
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
3152 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
3153
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
3154 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
3155 {
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
3156 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
3157 idx = lvar.lv_idx;
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
3158 if (lvar.lv_from_outer != 0)
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
3159 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
3160 else
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
3161 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
3162 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3163 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3164 {
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3165 // "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
3166 // 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
3167 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
3168 || 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
3169 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
3170
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
3171 // 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
3172 // 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
3173 // 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
3174 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
3175 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
3176 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3177 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3178 if (gen_load)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3179 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
3180 if (gen_load_outer > 0)
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
3181 {
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
3182 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
3183 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
3184 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3185 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3186
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3187 *arg = end;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3188
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3189 theend:
19818
c1c88b333481 patch 8.2.0465: Vim9: dead code and wrong return type
Bram Moolenaar <Bram@vim.org>
parents: 19785
diff changeset
3190 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
3191 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
3192 vim_free(name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3193 return res;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3194 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3195
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3196 static void
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3197 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
3198 {
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3199 int idx;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3200
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3201 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
3202 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
3203 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
3204 }
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3205
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3206 /*
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3207 * 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
3208 * 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
3209 */
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3210 static int
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3211 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
3212 {
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3213 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
3214 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
3215 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
3216 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
3217 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
3218 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
3219
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3220 // 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
3221 // correct.
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3222 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
3223 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
3224 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
3225 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
3226 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
3227 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
3228
24637
4a4f64cdc798 patch 8.2.2857: Vim9: exception in ISN_INSTR caught at wrong level
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
3229 if (expr_res == FAIL || trailing_error
4a4f64cdc798 patch 8.2.2857: Vim9: exception in ISN_INSTR caught at wrong level
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
3230 || ga_grow(&cctx->ctx_instr, 1) == FAIL)
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3231 {
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3232 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
3233 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
3234 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
3235 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
3236 return FAIL;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3237 }
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3238
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3239 // 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
3240 // 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
3241 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
3242 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
3243 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
3244
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3245 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
3246 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
3247 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
3248 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
3249 return OK;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3250 }
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3251
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3252 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3253 * 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
3254 * "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
3255 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3256 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
3257 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
3258 {
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3259 char_u *p = *arg;
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3260 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
3261 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
3262 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
3263
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
3264 for (;;)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3265 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3266 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
3267 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
3268 if (*p == ')')
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
3269 {
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
3270 *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
3271 return OK;
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
3272 }
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
3273 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
3274 {
fc3350a38389 patch 8.2.1719: Vim9: no error if comma is missing in between arguments
Bram Moolenaar <Bram@vim.org>
parents: 22326
diff changeset
3275 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
3276 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
3277 }
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
3278
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3279 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
3280 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
3281 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3282 ++*argcount;
19437
5d34ae66118e patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents: 19423
diff changeset
3283
24637
4a4f64cdc798 patch 8.2.2857: Vim9: exception in ISN_INSTR caught at wrong level
Bram Moolenaar <Bram@vim.org>
parents: 24614
diff changeset
3284 if (is_searchpair && *argcount >= 5
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3285 && 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
3286 {
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3287 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
3288
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3289 // {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
3290 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
3291 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
3292 }
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
3293
19437
5d34ae66118e patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents: 19423
diff changeset
3294 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
3295 {
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
3296 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
3297 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
3298 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3299 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
3300 {
5d34ae66118e patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents: 19423
diff changeset
3301 ++p;
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
3302 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
3303 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
3304 }
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
3305 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
3306 must_end = TRUE;
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3307 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
3308 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
3309 }
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3310 failret:
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
3311 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
3312 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3313 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3314
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3315 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3316 * 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
3317 * "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
3318 * "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
3319 * Instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3320 * EVAL arg1
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3321 * EVAL arg2
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3322 * BCALL / DCALL / UCALL
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3323 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3324 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
3325 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
3326 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
3327 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
3328 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
3329 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
3330 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
3331 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3332 char_u *name = *arg;
19257
5aab9c306181 patch 8.2.0187: reduntant code
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
3333 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
3334 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
3335 char_u namebuf[100];
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3336 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
3337 char_u *tofree = NULL;
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3338 int error = FCERR_NONE;
22914
54f796fb7cb2 patch 8.2.2004: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents: 22910
diff changeset
3339 ufunc_T *ufunc = NULL;
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3340 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
3341 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
3342 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
3343
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3344 // 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
3345 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
3346 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3347 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
3348 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
3349
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3350 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
3351 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
3352 (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
3353 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
3354 (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
3355 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
3356 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
3357 && !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
3358 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3359 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
3360
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3361 *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
3362 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
3363 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
3364 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
3365 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
3366 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
3367 ++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
3368 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
3369 }
20332
a407e243c55c patch 8.2.0721: Vim9: leaking memory when skipping
Bram Moolenaar <Bram@vim.org>
parents: 20328
diff changeset
3370 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
3371 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3372
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3373 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
3374 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
3375
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3376 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
3377 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
3378 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
3379 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3380 }
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3381 vim_strncpy(namebuf, *arg, varlen);
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3382 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
3383
24608
cb031f421ece patch 8.2.2843: Vim9: skip argument to searchpairpos() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
3384 // 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
3385 // differently.
cb031f421ece patch 8.2.2843: Vim9: skip argument to searchpairpos() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
3386 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
3387 || (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
3388 || (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
3389 || (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
3390
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3391 *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
3392 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
3393 goto theend;
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3394
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3395 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
3396 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
3397 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3398 int idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3399
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3400 // builtin function
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3401 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
3402 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
3403 {
23816
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23806
diff changeset
3404 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
3405 {
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23806
diff changeset
3406 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
3407 goto theend;
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23806
diff changeset
3408 }
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23806
diff changeset
3409
22633
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
3410 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
3411 {
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
3412 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
3413 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
3414 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
3415
22772
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
3416 // 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
3417 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
3418 {
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
3419 // 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
3420 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
3421 idx = -1;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
3422 }
22637
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3423 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
3424 {
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3425 // 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
3426 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
3427 idx = -1;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3428 }
22633
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
3429 }
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
3430
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
3431 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
3432 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
3433 }
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
3434 else
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
3435 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
3436 goto theend;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3437 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3438
22910
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
3439 // 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
3440 // 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
3441 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
3442 && 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
3443 {
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
3444 // 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
3445 // 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
3446 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
3447 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
3448 {
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
3449 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
3450 goto theend;
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
3451 }
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3452 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3453
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3454 // 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
3455 // 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
3456 // 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
3457 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
3458 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
3459 && 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
3460 {
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
3461 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
3462 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
3463
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
3464 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
3465 goto theend;
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3466 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3467
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
3468 // 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
3469 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
3470 {
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
3471 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
3472 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
3473 }
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
3474
20140
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20138
diff changeset
3475 // 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
3476 // 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
3477 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
3478 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
3479 else
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20138
diff changeset
3480 semsg(_(e_unknownfunc), namebuf);
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3481
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3482 theend:
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3483 vim_free(tofree);
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3484 return res;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3485 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3486
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3487 // 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
3488 #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
3489
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3490 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3491 * 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
3492 * 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
3493 * 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
3494 * 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
3495 * valid name.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3496 */
22936
00b0275ffe7f patch 8.2.2015: Vim9: literal dict #{} is not like any other language
Bram Moolenaar <Bram@vim.org>
parents: 22932
diff changeset
3497 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
3498 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
3499 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3500 char_u *p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3501
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3502 // 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
3503 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
3504 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3505
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3506 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
3507 // 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
3508 // 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
3509 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
3510 || !use_namespace
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3511 || 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
3512 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3513 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3514 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3515
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3516 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3517 * 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
3518 * 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
3519 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3520 char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3521 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
3522 {
19583
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
3523 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
3524 typval_T rettv;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3525
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3526 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
3527 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3528
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3529 // 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
3530 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
3531 p = arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3532 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3533 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3534 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3535
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3536 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3537 * 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
3538 * "*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
3539 * 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
3540 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3541 static int
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3542 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
3543 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3544 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
3545 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
3546 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
3547 int is_const;
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3548 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
3549
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3550 for (;;)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3551 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3552 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
3553 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3554 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
3555 return FAIL;
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3556 }
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
3557 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
3558 {
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
3559 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
3560 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
3561 }
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3562 if (*p == ']')
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3563 {
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3564 ++p;
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3565 break;
19830
6500dcaf8e1a patch 8.2.0471: missing change to compile_list()
Bram Moolenaar <Bram@vim.org>
parents: 19822
diff changeset
3566 }
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3567 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
3568 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3569 if (!is_const)
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3570 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
3571 ++count;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3572 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
3573 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3574 ++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
3575 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
3576 {
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
3577 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
3578 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
3579 }
bcd08812cde3 patch 8.2.1159: Vim9: no error for missing space after a comma
Bram Moolenaar <Bram@vim.org>
parents: 21210
diff changeset
3580 }
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3581 whitep = p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3582 p = skipwhite(p);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3583 }
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3584 *arg = p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3585
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3586 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
3587 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
3588 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3589
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3590 /*
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
3591 * 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
3592 * "*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
3593 * 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
3594 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3595 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3596 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
3597 {
23368
a7cbdb9294c4 patch 8.2.2227: Vim9: recognizing lambda is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 23364
diff changeset
3598 int r;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3599 typval_T rettv;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3600 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
3601 evalarg_T evalarg;
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
3602
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
3603 CLEAR_FIELD(evalarg);
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
3604 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
3605 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
3606
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3607 // 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
3608 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
3609 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
3610 {
1064b9f05b0a patch 8.2.1862: vim9: memory leak when compiling lambda fails
Bram Moolenaar <Bram@vim.org>
parents: 22614
diff changeset
3611 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
3612 return r;
22627
1064b9f05b0a patch 8.2.1862: vim9: memory leak when compiling lambda fails
Bram Moolenaar <Bram@vim.org>
parents: 22614
diff changeset
3613 }
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
3614
23318
c76240efdf02 patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents: 23310
diff changeset
3615 // "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
3616 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
3617 ++ufunc->uf_refcount;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
3618 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
3619
24890
0cba2be8cbd7 patch 8.2.2983: Vim9: an inline function requires specifying the return type
Bram Moolenaar <Bram@vim.org>
parents: 24874
diff changeset
3620 // Compile it here to get the return type. The return type is optional,
0cba2be8cbd7 patch 8.2.2983: Vim9: an inline function requires specifying the return type
Bram Moolenaar <Bram@vim.org>
parents: 24874
diff changeset
3621 // when it's missing use t_unknown. This is recognized in
0cba2be8cbd7 patch 8.2.2983: Vim9: an inline function requires specifying the return type
Bram Moolenaar <Bram@vim.org>
parents: 24874
diff changeset
3622 // compile_return().
0cba2be8cbd7 patch 8.2.2983: Vim9: an inline function requires specifying the return type
Bram Moolenaar <Bram@vim.org>
parents: 24874
diff changeset
3623 if (ufunc->uf_ret_type->tt_type == VAR_VOID)
0cba2be8cbd7 patch 8.2.2983: Vim9: an inline function requires specifying the return type
Bram Moolenaar <Bram@vim.org>
parents: 24874
diff changeset
3624 ufunc->uf_ret_type = &t_unknown;
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
3625 compile_def_function(ufunc, FALSE, COMPILE_TYPE(ufunc), cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3626
24190
5f3a2d31c48d patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents: 24188
diff changeset
3627 // 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
3628 // 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
3629 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
3630 {
5f3a2d31c48d patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents: 24188
diff changeset
3631 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
3632
5f3a2d31c48d patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents: 24188
diff changeset
3633 *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
3634 + off;
5f3a2d31c48d patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents: 24188
diff changeset
3635 }
5f3a2d31c48d patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents: 24188
diff changeset
3636
21220
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21218
diff changeset
3637 clear_evalarg(&evalarg, NULL);
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21218
diff changeset
3638
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
3639 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
3640 {
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
3641 // 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
3642 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
3643
22324
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
3644 // 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
3645 // 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
3646 // 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
3647 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
3648 }
21353
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
3649
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
3650 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
3651 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3652 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3653
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3654 /*
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
3655 * 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
3656 * "*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
3657 * 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
3658 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3659 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
3660 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
3661 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3662 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
3663 int count = 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3664 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
3665 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
3666 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
3667 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
3668 int is_const;
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3669 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
3670
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3671 if (d == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3672 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
3673 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
3674 return FAIL;
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3675 for (;;)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3676 {
22936
00b0275ffe7f patch 8.2.2015: Vim9: literal dict #{} is not like any other language
Bram Moolenaar <Bram@vim.org>
parents: 22932
diff changeset
3677 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
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 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
3680 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3681 *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
3682 goto failret;
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3683 }
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3684
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3685 if (**arg == '}')
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3686 break;
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3687
23088
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3688 if (**arg == '[')
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3689 {
22936
00b0275ffe7f patch 8.2.2015: Vim9: literal dict #{} is not like any other language
Bram Moolenaar <Bram@vim.org>
parents: 22932
diff changeset
3690 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
3691
23088
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3692 // {[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
3693 *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
3694 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
3695 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3696 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
3697 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
3698 {
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23816
diff changeset
3699 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
3700
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23816
diff changeset
3701 // 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
3702 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
3703 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
3704 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
3705 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3706 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
3707 key = isn->isn_arg.string;
24796
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
3708 else if (may_generate_2STRING(-1, FALSE, cctx) == FAIL)
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
3709 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
3710 *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
3711 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
3712 {
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
3713 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
3714 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
3715 }
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
3716 ++*arg;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3717 }
23088
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3718 else
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3719 {
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3720 // {"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
3721 // {'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
3722 // {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
3723 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
3724 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
3725 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
3726 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
3727 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
3728 }
19181
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 // 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
3731 if (key != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3732 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3733 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
3734 if (item != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3735 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3736 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
3737 goto failret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3738 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3739 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
3740 if (item != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3741 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3742 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
3743 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
3744 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
3745 dictitem_free(item);
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 }
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 if (**arg != ':')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3750 {
21759
25b659fa5ca5 patch 8.2.1429: Vim9: no error for missing white after : in dict
Bram Moolenaar <Bram@vim.org>
parents: 21755
diff changeset
3751 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
3752 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
3753 else
25b659fa5ca5 patch 8.2.1429: Vim9: no error for missing white after : in dict
Bram Moolenaar <Bram@vim.org>
parents: 21755
diff changeset
3754 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
3755 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3756 }
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3757 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
3758 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
3759 {
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
3760 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
3761 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
3762 }
25b659fa5ca5 patch 8.2.1429: Vim9: no error for missing white after : in dict
Bram Moolenaar <Bram@vim.org>
parents: 21755
diff changeset
3763
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3764 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
3765 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3766 *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
3767 goto failret;
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3768 }
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3769
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3770 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
3771 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3772 if (!is_const)
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3773 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
3774 ++count;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3775
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3776 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
3777 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
3778 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3779 *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
3780 goto failret;
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3781 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3782 if (**arg == '}')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3783 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3784 if (**arg != ',')
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 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
3787 goto failret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3788 }
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
3789 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
3790 {
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
3791 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
3792 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
3793 }
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3794 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
3795 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
3796 {
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
3797 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
3798 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
3799 }
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
3800 *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
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 *arg = *arg + 1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3804
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3805 // 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
3806 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
3807 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
3808 *arg += STRLEN(*arg);
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3809
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3810 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
3811 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
3812 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
3813
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3814 failret:
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3815 if (*arg == NULL)
22508
ac8c4a8b8cba patch 8.2.1802: Vim9: crash with unterminated dict
Bram Moolenaar <Bram@vim.org>
parents: 22504
diff changeset
3816 {
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3817 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
3818 *arg = (char_u *)"";
ac8c4a8b8cba patch 8.2.1802: Vim9: crash with unterminated dict
Bram Moolenaar <Bram@vim.org>
parents: 22504
diff changeset
3819 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3820 dict_unref(d);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3821 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3822 }
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3825 * Compile "&option".
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 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3828 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
3829 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3830 typval_T rettv;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3831 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
3832 int ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3833
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3834 // 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
3835 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
3836 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
3837 if (ret == OK)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3838 {
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21116
diff changeset
3839 // 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
3840 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
3841 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
3842 : 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
3843
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3844 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
3845 vim_free(name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3846 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3847 clear_tv(&rettv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3848
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3849 return ret;
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
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 * Compile "$VAR".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3854 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3855 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3856 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
3857 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3858 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
3859 int len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3860 int ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3861 char_u *name;
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 ++*arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3864 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
3865 if (len == 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3866 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
3867 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
3868 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3869 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3870
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21116
diff changeset
3871 // 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
3872 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
3873 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
3874 vim_free(name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3875 return ret;
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
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3878 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3879 * Compile "@r".
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 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3882 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
3883 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3884 int ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3885
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3886 ++*arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3887 if (**arg == NUL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3888 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
3889 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
3890 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3891 }
21612
c495d3e30f4b patch 8.2.1356: Vim9: cannot get the percent register
Bram Moolenaar <Bram@vim.org>
parents: 21610
diff changeset
3892 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
3893 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3894 emsg_invreg(**arg);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3895 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3896 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3897 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
3898 ++*arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3899 return ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3900 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3901
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3902 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3903 * 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
3904 * 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
3905 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3906 static int
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3907 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
3908 {
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3909 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
3910
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3911 // 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
3912 while (p > start)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3913 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3914 --p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3915 if (*p == '-' || *p == '+')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3916 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3917 // 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
3918 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3919 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
3920 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3921 if (*p == '-')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3922 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
3923 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3924 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3925 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3926 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3927 varnumber_T val;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3928 int error = FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3929
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3930 // 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
3931 // here
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3932 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
3933 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3934 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
3935 clear_tv(rettv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3936 if (error)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3937 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3938 if (*p == '-')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3939 val = -val;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3940 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
3941 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
3942 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3943 }
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3944 else if (numeric_only)
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3945 {
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3946 ++p;
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3947 break;
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3948 }
22606
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
3949 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
3950 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3951 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
3952
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3953 // '!' 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
3954 clear_tv(rettv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3955 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
3956 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
3957 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3958 }
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3959 *end = p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3960 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3961 }
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3964 * 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
3965 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3966 static void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3967 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
3968 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3969 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
3970 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3971 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
3972 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
3973 *arg += 6;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3974 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3975 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
3976 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3977 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
3978 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
3979 *arg += 7;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3980 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3981 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
3982 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3983 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
3984 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
3985 *arg += 6;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3986 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3987 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
3988 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3989 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
3990 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
3991 *arg += 6;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3992 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3993 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3994
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
3995 exprtype_T
20305
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3996 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
3997 {
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
3998 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
3999 int i;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4000
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4001 switch (p[0])
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4002 {
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4003 case '=': if (p[1] == '=')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4004 type = EXPR_EQUAL;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4005 else if (p[1] == '~')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4006 type = EXPR_MATCH;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4007 break;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4008 case '!': if (p[1] == '=')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4009 type = EXPR_NEQUAL;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4010 else if (p[1] == '~')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4011 type = EXPR_NOMATCH;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4012 break;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4013 case '>': if (p[1] != '=')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4014 {
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4015 type = EXPR_GREATER;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4016 *len = 1;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4017 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4018 else
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4019 type = EXPR_GEQUAL;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4020 break;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4021 case '<': if (p[1] != '=')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4022 {
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4023 type = EXPR_SMALLER;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4024 *len = 1;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4025 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4026 else
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4027 type = EXPR_SEQUAL;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4028 break;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4029 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
4030 {
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4031 // "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
4032 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
4033 *len = 5;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4034 i = p[*len];
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4035 if (!isalnum(i) && i != '_')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4036 {
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4037 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
4038 *type_is = TRUE;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4039 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4040 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4041 break;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4042 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4043 return type;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4044 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4045
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
4046 /*
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4047 * 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
4048 */
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4049 static void
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4050 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
4051 {
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4052 evalarg_T evalarg;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4053
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4054 CLEAR_FIELD(evalarg);
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4055 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
4056 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
4057 }
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4058
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4059 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4060 * 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
4061 * 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
4062 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4063 static int
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4064 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
4065 {
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4066 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
4067
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4068 // 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
4069 while (p > start)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4070 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4071 --p;
22932
87b62395a4d1 patch 8.2.2013: Vim9: not skipping white space after unary minus
Bram Moolenaar <Bram@vim.org>
parents: 22926
diff changeset
4072 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
4073 --p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4074 if (*p == '-' || *p == '+')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4075 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4076 int negate = *p == '-';
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4077 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4078
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4079 // TODO: check type
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4080 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
4081 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4082 --p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4083 if (*p == '-')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4084 negate = !negate;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4085 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4086 // 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
4087 if (negate)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4088 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
4089 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4090 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
4091 if (isn == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4092 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4093 }
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4094 else if (numeric_only)
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4095 {
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4096 ++p;
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4097 break;
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4098 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4099 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4100 {
22606
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
4101 int invert = *p == '!';
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
4102
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
4103 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
4104 {
22606
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
4105 if (p[-1] == '!')
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
4106 invert = !invert;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4107 --p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4108 }
24796
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
4109 if (generate_2BOOL(cctx, invert, -1) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4110 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4111 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4112 }
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4113 *end = p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4114 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4115 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4116
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4117 /*
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4118 * Compile "(expression)": recursive!
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4119 * Return FAIL/OK.
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4120 */
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4121 static int
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4122 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
4123 {
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
4124 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
4125 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
4126
455ad460ff4f patch 8.2.2349: Vim9: cannot handle line break after parenthesis at line end
Bram Moolenaar <Bram@vim.org>
parents: 23586
diff changeset
4127 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
4128 return FAIL;
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4129 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
4130 {
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4131 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
4132 }
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4133 else
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4134 {
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4135 // 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
4136 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
4137 return FAIL;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4138 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
4139 }
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
4140 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
4141 return FAIL;
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4142 if (**arg == ')')
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4143 ++*arg;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4144 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
4145 {
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4146 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
4147 ret = FAIL;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4148 }
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4149 return ret;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4150 }
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4151
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4152 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4153 * 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
4154 * 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
4155 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4156 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4157 compile_subscript(
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4158 char_u **arg,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4159 cctx_T *cctx,
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4160 char_u *start_leader,
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4161 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
4162 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
4163 {
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4164 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
4165
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4166 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4167 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
4168 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
4169
21353
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
4170 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
4171 {
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4172 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
4173
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
4174 // 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
4175 // 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
4176 // 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
4177 if (next != NULL &&
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
4178 ((next[0] == '-' && next[1] == '>'
24852
3c8bd1d392d1 patch 8.2.2964: Vim9: hang when using space after ->
Bram Moolenaar <Bram@vim.org>
parents: 24834
diff changeset
4179 && (next[2] == '{'
3c8bd1d392d1 patch 8.2.2964: Vim9: hang when using space after ->
Bram Moolenaar <Bram@vim.org>
parents: 24834
diff changeset
4180 || ASCII_ISALPHA(*skipwhite(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
4181 || (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
4182 {
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
4183 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
4184 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
4185 return FAIL;
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4186 *arg = next;
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4187 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
4188 }
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
4189 }
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
4190
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 23199
diff changeset
4191 // 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
4192 // 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
4193 if (**arg == '(')
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4194 {
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
4195 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
4196 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
4197 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
4198
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4199 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
4200 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4201 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
4202
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4203 // 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
4204 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
4205
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4206 *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
4207 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
4208 return FAIL;
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4209 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
4210 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4211 }
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4212 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
4213 {
21465
b5d4ab124782 patch 8.2.1283: Vim9: error for misplaced -> lacks argument
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
4214 char_u *pstart = p;
b5d4ab124782 patch 8.2.1283: Vim9: error for misplaced -> lacks argument
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
4215
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4216 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
4217 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4218 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
4219
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4220 // something->method()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4221 // 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
4222 // -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
4223 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
4224 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4225
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4226 p += 2;
20949
62912ad41aff patch 8.2.1026: Vim9: cannot break the line after "->"
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
4227 *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
4228 // 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
4229 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
4230 {
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4231 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
4232 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
4233 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
4234 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
4235 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
4236 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
4237 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
4238
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4239 // 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
4240 // 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
4241 //
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4242 // 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
4243 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
4244 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
4245
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4246 // 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
4247 // 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
4248 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
4249
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4250 // 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
4251 if (**arg != '(')
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4252 {
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
4253 if (*skipwhite(*arg) == '(')
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
4254 emsg(_(e_nowhitespace));
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
4255 else
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
4256 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
4257 return FAIL;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4258 }
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4259 *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
4260 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
4261 return FAIL;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4262
24361
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4263 // 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
4264 // 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
4265 // 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
4266 // expects.
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4267 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
4268 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
4269 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
4270 {
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4271 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
4272 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
4273
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4274 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
4275 return FAIL;
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4276 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
4277 + 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
4278 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
4279 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
4280 + 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
4281 ((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
4282 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
4283 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
4284 + 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
4285 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
4286 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
4287
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4288 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
4289 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
4290 ((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
4291 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
4292 * (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
4293 ((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
4294 }
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4295
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4296 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
4297 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
4298 (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
4299 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4300 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4301 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4302 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4303 // 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
4304 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
4305 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
4306 {
21465
b5d4ab124782 patch 8.2.1283: Vim9: error for misplaced -> lacks argument
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
4307 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
4308 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
4309 }
19848
36d629aa3d6e patch 8.2.0480: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19830
diff changeset
4310 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
4311 p += 2;
21650
79a8d723a3d2 patch 8.2.1375: Vim9: method name with digit not accepted
Bram Moolenaar <Bram@vim.org>
parents: 21648
diff changeset
4312 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
4313 ;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4314 if (*p != '(')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4315 {
19848
36d629aa3d6e patch 8.2.0480: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19830
diff changeset
4316 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
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 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4319 // 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
4320 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
4321 return FAIL;
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 }
21562
55aa283a0e5e patch 8.2.1331: Vim9: :echo with two lists doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21558
diff changeset
4324 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
4325 {
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4326 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
4327
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
4328 // 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
4329 // 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
4330 // 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
4331 // 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
4332 // 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
4333 // 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
4334 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
4335 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4336 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
4337
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4338 ++p;
21248
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
4339 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
4340 return FAIL;
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4341 if (**arg == ':')
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4342 {
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4343 // 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
4344 generate_PUSHNR(cctx, 0);
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4345 }
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4346 else
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4347 {
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4348 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
4349 return FAIL;
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4350 if (**arg == ':')
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4351 {
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
4352 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
4353 ":", *arg);
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4354 return FAIL;
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4355 }
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
4356 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
4357 return FAIL;
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4358 *arg = skipwhite(*arg);
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4359 }
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4360 if (**arg == ':')
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4361 {
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4362 is_slice = TRUE;
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4363 ++*arg;
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4364 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
4365 {
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
4366 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
4367 ":", *arg);
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4368 return FAIL;
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4369 }
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
4370 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
4371 return FAIL;
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4372 if (**arg == ']')
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4373 // 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
4374 generate_PUSHNR(cctx, -1);
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4375 else
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4376 {
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4377 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
4378 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
4379 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
4380 return FAIL;
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4381 *arg = skipwhite(*arg);
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4382 }
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4383 }
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4384
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4385 if (**arg != ']')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4386 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4387 emsg(_(e_missbrac));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4388 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4389 }
19342
8ff84bc1c89b patch 8.2.0229: compare instructions not tested
Bram Moolenaar <Bram@vim.org>
parents: 19336
diff changeset
4390 *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
4391
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
4392 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
4393 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4394 }
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4395 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
4396 {
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4397 // 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
4398 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
4399 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4400 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
4401
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4402 *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
4403 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
4404 {
a1b3804163ca patch 8.2.1789: Vim9: crash with invalid list constant
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
4405 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
4406 return FAIL;
22482
a1b3804163ca patch 8.2.1789: Vim9: crash with invalid list constant
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
4407 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4408 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
4409 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
4410 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
4411 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
4412 if (p == *arg)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4413 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
4414 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
4415 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4416 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
4417 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
4418 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4419 *arg = p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4420 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4421 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4422 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4423 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4424
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4425 // 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
4426 // 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
4427 // 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
4428 // 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
4429
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4430 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4431 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4432
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4433 /*
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4434 * 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
4435 * "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
4436 *
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4437 * 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
4438 * 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
4439 *
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4440 * 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
4441 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4442
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4443 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4444 * number number constant
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4445 * 0zFFFFFFFF Blob constant
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4446 * "string" string constant
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4447 * '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
4448 * &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
4449 * @r register contents
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4450 * identifier variable value
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4451 * function() function call
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4452 * $VAR environment variable
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4453 * (expression) nested expression
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4454 * [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
4455 * {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
4456 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4457 * Also handle:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4458 * ! 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
4459 * - 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
4460 * + 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
4461 * 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
4462 * 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
4463 * 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
4464 * 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
4465 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4466 static int
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4467 compile_expr7(
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4468 char_u **arg,
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4469 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
4470 ppconst_T *ppconst)
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4471 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4472 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
4473 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
4474 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
4475 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
4476
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4477 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
4478
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4479 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4480 * 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
4481 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4482 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
4483 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
4484 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4485 end_leader = *arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4486
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4487 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
4488 switch (**arg)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4489 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4490 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4491 * Number constant.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4492 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4493 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
4494 case '1':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4495 case '2':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4496 case '3':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4497 case '4':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4498 case '5':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4499 case '6':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4500 case '7':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4501 case '8':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4502 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
4503 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
4504 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
4505 // 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
4506 // 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
4507 // '!'.
a7e0091a4669 patch 8.2.1421: Vim9: handling "+" and "-" before number differs from script
Bram Moolenaar <Bram@vim.org>
parents: 21739
diff changeset
4508 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
4509 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
4510 {
a7e0091a4669 patch 8.2.1421: Vim9: handling "+" and "-" before number differs from script
Bram Moolenaar <Bram@vim.org>
parents: 21739
diff changeset
4511 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
4512 return FAIL;
a7e0091a4669 patch 8.2.1421: Vim9: handling "+" and "-" before number differs from script
Bram Moolenaar <Bram@vim.org>
parents: 21739
diff changeset
4513 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4514 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4515
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4516 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4517 * String constant: "string".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4518 */
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21116
diff changeset
4519 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
4520 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4521 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4522
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4523 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4524 * 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
4525 */
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21116
diff changeset
4526 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
4527 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4528 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4529
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4530 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4531 * Constant Vim variable.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4532 */
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4533 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
4534 ret = NOTDONE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4535 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4536
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4537 /*
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4538 * "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
4539 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4540 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
4541 && !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
4542 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4543 *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
4544 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
4545 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
4546 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4547 else
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4548 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
4549 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4550
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4551 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4552 * "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
4553 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4554 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
4555 && !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
4556 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4557 *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
4558 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
4559 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
4560 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4561 else
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4562 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
4563 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4564
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4565 /*
23497
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4566 * "null" constant
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4567 */
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4568 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
4569 && !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
4570 {
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4571 *arg += 4;
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4572 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
4573 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
4574 }
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4575 else
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4576 ret = NOTDONE;
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4577 break;
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4578
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4579 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4580 * List: [expr, expr]
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4581 */
23806
c0f2c6c56147 patch 8.2.2444: Vim9: compile error with combination of operator and list
Bram Moolenaar <Bram@vim.org>
parents: 23735
diff changeset
4582 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
4583 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
4584 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
4585 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4586
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4587 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4588 * 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
4589 */
23806
c0f2c6c56147 patch 8.2.2444: Vim9: compile error with combination of operator and list
Bram Moolenaar <Bram@vim.org>
parents: 23735
diff changeset
4590 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
4591 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
4592 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
4593 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4594
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4595 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4596 * Option value: &name
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4597 */
21903
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4598 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
4599 return FAIL;
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4600 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
4601 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4602
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4603 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4604 * Environment variable: $VAR.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4605 */
21903
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4606 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
4607 return FAIL;
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4608 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
4609 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4610
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4611 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4612 * Register contents: @r.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4613 */
21903
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4614 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
4615 return FAIL;
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4616 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
4617 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4618 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4619 * 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
4620 * 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
4621 * 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
4622 */
23368
a7cbdb9294c4 patch 8.2.2227: Vim9: recognizing lambda is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 23364
diff changeset
4623 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
4624 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
4625 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
4626 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
4627 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4628
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4629 default: ret = NOTDONE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4630 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4631 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4632 if (ret == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4633 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4634
20336
2fd980fb9ab3 patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents: 20334
diff changeset
4635 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
4636 {
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
4637 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
4638 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
4639 else
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4640 // 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
4641 // 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
4642 ++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
4643 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4644 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
4645 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4646 char_u *p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4647 int r;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4648
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4649 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
4650 {
24158
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
4651 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
4652 {
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
4653 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
4654 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
4655 else
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
4656 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
4657 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4658 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4659 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4660
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4661 // "name" or "name()"
19583
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
4662 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
4663 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
4664 {
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
4665 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
4666 return FAIL;
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
4667 }
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
4668
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4669 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
4670 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4671 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
4672 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4673 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
4674 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4675 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
4676 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
4677 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
4678 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4679 if (r == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4680 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4681 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4682
20322
a3e78893a90b patch 8.2.0716: Vim9: another memory leak
Bram Moolenaar <Bram@vim.org>
parents: 20320
diff changeset
4683 // Handle following "[]", ".member", etc.
a3e78893a90b patch 8.2.0716: Vim9: another memory leak
Bram Moolenaar <Bram@vim.org>
parents: 20320
diff changeset
4684 // 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
4685 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
4686 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
4687 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
4688 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
4689 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4690 // 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
4691 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
4692 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
4693 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
4694 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
4695 }
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4696 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
4697 return FAIL;
20322
a3e78893a90b patch 8.2.0716: Vim9: another memory leak
Bram Moolenaar <Bram@vim.org>
parents: 20320
diff changeset
4698 return OK;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4699 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4700
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4701 /*
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4702 * 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
4703 */
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4704 void
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4705 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
4706 {
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4707 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
4708
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4709 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
4710 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
4711 }
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4712
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4713 /*
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4714 * <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
4715 */
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4716 static int
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4717 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
4718 {
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4719 type_T *want_type = NULL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4720
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4721 // Recognize <type>
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4722 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
4723 {
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4724 ++*arg;
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
4725 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
4726 if (want_type == NULL)
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4727 return FAIL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4728
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4729 if (**arg != '>')
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4730 {
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4731 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
4732 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
4733 else
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
4734 emsg(_(e_missing_gt));
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4735 return FAIL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4736 }
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4737 ++*arg;
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
4738 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
4739 return FAIL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4740 }
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4741
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4742 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
4743 return FAIL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4744
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4745 if (want_type != NULL)
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4746 {
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4747 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
4748 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
4749 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
4750
3261e28c638a patch 8.2.1455: Vim9: crash when using typecast before constant
Bram Moolenaar <Bram@vim.org>
parents: 21809
diff changeset
4751 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
4752 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
4753 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
4754 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
4755 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
4756 {
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
4757 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
4758 return FAIL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4759 }
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4760 }
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4761
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4762 return OK;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4763 }
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4764
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4765 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4766 * * number multiplication
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4767 * / number division
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4768 * % number modulo
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4769 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4770 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
4771 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
4772 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4773 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
4774 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
4775 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
4776
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4777 // get the first expression
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4778 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
4779 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4780
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4781 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4782 * 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
4783 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4784 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4785 {
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4786 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
4787 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
4788 break;
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4789 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
4790 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4791 *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
4792 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
4793 }
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4794
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4795 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
4796 {
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4797 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
4798 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4799 }
23106
b0c88aa0175b patch 8.2.2099: Vim9: some checks are not tested
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
4800 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
4801 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4802
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4803 // get the second expression
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4804 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
4805 return FAIL;
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4806
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4807 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
4808 && 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
4809 && 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
4810 {
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23669
diff changeset
4811 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
4812 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
4813 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
4814 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
4815
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4816 // 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
4817 switch (*op)
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4818 {
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4819 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
4820 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
4821 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
4822 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
4823 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
4824 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
4825 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
4826 break;
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4827 }
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23669
diff changeset
4828 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
4829 return FAIL;
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4830 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
4831 --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
4832 }
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4833 else
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4834 {
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4835 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
4836 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
4837 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4838 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4839
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4840 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4841 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4842
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4843 /*
24085
23c692a4bc36 patch 8.2.2584: Vim9: type error for assigning "any" to a list
Bram Moolenaar <Bram@vim.org>
parents: 24067
diff changeset
4844 * + 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
4845 * - number subtraction
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4846 * .. string concatenation
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4847 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4848 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
4849 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
4850 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4851 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
4852 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
4853 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
4854 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
4855
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4856 // 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
4857 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
4858 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4859
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4860 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4861 * 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
4862 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4863 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4864 {
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4865 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
4866 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
4867 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
4868 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
4869 // 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
4870 // 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
4871 break;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4872 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
4873 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
4874 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4875 *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
4876 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
4877 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4878
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4879 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
4880 {
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4881 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
4882 return FAIL;
19181
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
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
4885 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
4886 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4887
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4888 // 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
4889 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
4890 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
4891
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4892 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
4893 && (*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
4894 ? (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
4895 && 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
4896 : (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
4897 && 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
4898 {
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4899 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
4900 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
4901
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4902 // 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
4903 if (*op == '+')
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4904 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
4905 else if (*op == '-')
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4906 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
4907 else
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4908 {
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4909 // concatenate constant strings
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4910 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
4911 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
4912 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
4913
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4914 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
4915 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
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 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
4918 return FAIL;
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4919 }
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4920 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
4921 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
4922 vim_free(s1);
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4923 vim_free(s2);
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4924 }
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4925 --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
4926 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4927 else
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4928 {
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4929 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
4930 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
4931 if (*op == '.')
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4932 {
24796
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
4933 if (may_generate_2STRING(-2, FALSE, cctx) == FAIL
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
4934 || may_generate_2STRING(-1, FALSE, cctx) == FAIL)
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4935 return FAIL;
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4936 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
4937 }
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4938 else
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4939 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
4940 }
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4941 }
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4942
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4943 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4944 }
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 * expr5a == expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4948 * expr5a =~ expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4949 * expr5a != expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4950 * expr5a !~ expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4951 * expr5a > expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4952 * expr5a >= expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4953 * expr5a < expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4954 * expr5a <= expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4955 * expr5a is expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4956 * expr5a isnot expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4957 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4958 * Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4959 * 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
4960 * 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
4961 * 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
4962 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4963 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
4964 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
4965 {
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
4966 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
4967 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
4968 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
4969 int len = 2;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4970 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
4971 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
4972
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4973 // 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
4974 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
4975 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4976
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4977 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
4978 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
4979
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4980 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4981 * 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
4982 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4983 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
4984 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4985 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
4986
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4987 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
4988 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4989 *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
4990 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
4991 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4992 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
4993 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4994 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
4995 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4996 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4997 // 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
4998 if (p[len] == '?')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4999 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5000 ic = TRUE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5001 ++len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5002 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5003 // 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
5004 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
5005 ++len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5006 // 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
5007
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
5008 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
5009 {
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
5010 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
5011 return FAIL;
19181
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
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5014 // 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
5015 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
5016 return FAIL;
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
5017
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5018 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
5019 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5020
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5021 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
5022 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5023 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
5024 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
5025 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
5026
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5027 // 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
5028 // 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
5029 // 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
5030 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
5031 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
5032 else
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5033 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5034 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
5035 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
5036 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
5037 ? 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
5038 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
5039 --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
5040 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5041 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
5042 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5043
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5044 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
5045 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
5046 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5047
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5048 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5049 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5050
20334
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
5051 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
5052
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5053 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5054 * Compile || or &&.
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 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
5057 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
5058 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
5059 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
5060 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
5061 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
5062 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
5063 {
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
5064 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
5065 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
5066 int opchar = *op;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5067
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5068 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
5069 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5070 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
5071 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
5072
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 * 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
5075 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5076 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
5077 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
5078 {
24331
bd010982f0be patch 8.2.2706: Vim9: wrong line number reported for boolean operator
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
5079 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
5080 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
5081 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
5082
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
5083 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
5084 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
5085 *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
5086 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
5087 }
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
5088
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
5089 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
5090 {
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
5091 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
5092 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
5093 return FAIL;
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
5094 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5095
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
5096 // 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
5097 // 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
5098 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
5099
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
5100 // 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
5101 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
5102 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
5103 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
5104 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
5105 {
24331
bd010982f0be patch 8.2.2706: Vim9: wrong line number reported for boolean operator
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
5106 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
5107 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
5108 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
5109 }
24331
bd010982f0be patch 8.2.2706: Vim9: wrong line number reported for boolean operator
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
5110 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
5111
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5112 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
5113 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5114 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
5115 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5116 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5117 *(((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
5118 ++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
5119 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
5120 ? 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
5121
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5122 // 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
5123 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
5124 {
545ff3b4543c patch 8.2.2101: Vim9: memory leak when literal dict has an error
Bram Moolenaar <Bram@vim.org>
parents: 23106
diff changeset
5125 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
5126 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
5127 }
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
5128
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5129 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
5130 : 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
5131 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5132 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
5133 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5134 }
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
5135
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
5136 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
5137 }
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5138 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
5139
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
5140 // 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
5141 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
5142 {
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
5143 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
5144 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
5145 }
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
5146
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5147 // 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
5148 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
5149 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5150 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5151
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5152 --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
5153 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
5154 + *(((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
5155 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
5156 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5157 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
5158 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5159
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5160 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5161 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5162
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5163 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5164 * 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
5165 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5166 * Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5167 * 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
5168 * 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
5169 * 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
5170 * 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
5171 * 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
5172 * 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
5173 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5174 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5175 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
5176 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
5177 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5178 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
5179
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5180 // 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
5181 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
5182 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5183
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5184 // || 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
5185 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
5186 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5187
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5188 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5189 * 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
5190 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5191 * Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5192 * 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
5193 * 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
5194 * 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
5195 * 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
5196 * 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
5197 * 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
5198 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5199 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5200 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
5201 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
5202 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5203 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
5204
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5205 // 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
5206 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
5207 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5208
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5209 // || 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
5210 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
5211 }
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5214 * 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
5215 * Produces instructions:
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5216 * 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
5217 * 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
5218 * EVAL expr1a
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5219 * JUMP_ALWAYS end
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5220 * alt: EVAL expr1b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5221 * end:
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5222 *
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5223 * Toplevel expression: expr2 ?? expr1
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5224 * Produces instructions:
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5225 * EVAL expr2 Push result of "expr2"
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5226 * 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
5227 * EVAL expr1
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5228 * end:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5229 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5230 static int
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
5231 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
5232 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5233 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
5234 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
5235 char_u *next;
20305
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
5236
21957
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
5237 // 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
5238 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
5239 {
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
5240 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
5241 return OK;
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
5242 }
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
5243
20305
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
5244 // 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
5245 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
5246 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5247
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
5248 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
5249 if (*p == '?')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5250 {
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5251 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
5252 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
5253 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
5254 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
5255 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
5256 isn_T *isn;
20966
0ee7de260208 patch 8.2.1034: compiler warning for uninitialized variables
Bram Moolenaar <Bram@vim.org>
parents: 20961
diff changeset
5257 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
5258 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
5259 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
5260 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
5261
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
5262 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
5263 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
5264 *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
5265 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
5266 }
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
5267
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5268 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
5269 {
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
5270 semsg(_(e_white_space_required_before_and_after_str_at_str),
24713
34a5329b85aa patch 8.2.2895: Vim9: random characters appear in some error messages
Bram Moolenaar <Bram@vim.org>
parents: 24679
diff changeset
5271 op_falsy ? "??" : "?", p);
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
5272 return FAIL;
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
5273 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5274
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5275 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
5276 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5277 // 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
5278 // 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
5279 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
5280 if (op_falsy)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5281 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
5282 else
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5283 {
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5284 int error = FALSE;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5285
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5286 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
5287 &error);
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5288 if (error)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5289 return FAIL;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5290 }
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5291 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
5292 (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
5293
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5294 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
5295 // "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
5296 generate_ppconst(cctx, ppconst);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5297 else
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5298 {
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5299 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
5300 --ppconst->pp_used;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5301 }
20328
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 else
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5304 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5305 generate_ppconst(cctx, ppconst);
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5306 if (op_falsy)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5307 end_idx = instr->ga_len;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5308 generate_JUMP(cctx, op_falsy
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5309 ? 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
5310 if (op_falsy)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5311 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
5312 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5313
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5314 // 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
5315 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
5316 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
5317 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
5318 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5319
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5320 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
5321 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5322 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
5323
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5324 if (!op_falsy)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5325 {
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5326 // remember the type and drop it
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5327 --stack->ga_len;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5328 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
5329
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5330 end_idx = instr->ga_len;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5331 generate_JUMP(cctx, JUMP_ALWAYS, 0);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5332
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5333 // jump here from JUMP_IF_FALSE
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5334 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
5335 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
5336 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5337 }
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5338
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5339 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
5340 {
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5341 // Check for the ":".
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5342 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
5343 if (*p != ':')
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5344 {
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5345 emsg(_(e_missing_colon));
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5346 return FAIL;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5347 }
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5348 if (next != NULL)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5349 {
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5350 *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
5351 p = skipwhite(*arg);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5352 }
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5353
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5354 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
5355 {
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
5356 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
5357 ":", p);
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5358 return FAIL;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5359 }
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5360
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5361 // evaluate the third expression
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5362 if (has_const_expr)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5363 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
5364 ? 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
5365 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
5366 return FAIL;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5367 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
5368 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
5369 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5370
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5371 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
5372 {
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5373 type_T **typep;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5374
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5375 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
5376
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5377 // 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
5378 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
5379 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
5380
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5381 // 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
5382 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
5383 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
5384 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5385
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5386 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
5387 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5388 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
5389 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5390
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5391 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5392 * Toplevel expression.
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5393 * 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
5394 * 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
5395 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5396 static int
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5397 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
5398 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5399 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
5400
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5401 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
5402 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
5403 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5404 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
5405 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
5406 }
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5407 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
5408 *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
5409 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
5410 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5411 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5412 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5413
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5414 /*
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5415 * Toplevel expression.
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5416 */
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5417 static int
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5418 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
5419 {
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5420 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
5421 }
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5422
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5423 /*
24645
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
5424 * Compile "return [expr]".
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
5425 * When "legacy" is TRUE evaluate [expr] with legacy syntax
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5426 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5427 static char_u *
24645
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
5428 compile_return(char_u *arg, int check_return_type, int legacy, 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
5429 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5430 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
5431 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
5432 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
5433
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5434 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
5435 {
24645
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
5436 if (legacy)
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
5437 {
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
5438 int save_flags = cmdmod.cmod_flags;
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
5439
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
5440 generate_LEGACY_EVAL(cctx, p);
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
5441 if (need_type(&t_any, cctx->ctx_ufunc->uf_ret_type, -1,
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
5442 0, cctx, FALSE, FALSE) == FAIL)
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
5443 return NULL;
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
5444 cmdmod.cmod_flags |= CMOD_LEGACY;
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
5445 (void)skip_expr(&p, NULL);
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
5446 cmdmod.cmod_flags = save_flags;
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
5447 }
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
5448 else
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
5449 {
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
5450 // compile return argument into instructions
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
5451 if (compile_expr0(&p, cctx) == FAIL)
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
5452 return NULL;
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
5453 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5454
22926
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5455 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
5456 {
24890
0cba2be8cbd7 patch 8.2.2983: Vim9: an inline function requires specifying the return type
Bram Moolenaar <Bram@vim.org>
parents: 24874
diff changeset
5457 // "check_return_type" with uf_ret_type set to &t_unknown is used
0cba2be8cbd7 patch 8.2.2983: Vim9: an inline function requires specifying the return type
Bram Moolenaar <Bram@vim.org>
parents: 24874
diff changeset
5458 // for an inline function without a specified return type. Set the
0cba2be8cbd7 patch 8.2.2983: Vim9: an inline function requires specifying the return type
Bram Moolenaar <Bram@vim.org>
parents: 24874
diff changeset
5459 // return type here.
22926
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5460 stack_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
24890
0cba2be8cbd7 patch 8.2.2983: Vim9: an inline function requires specifying the return type
Bram Moolenaar <Bram@vim.org>
parents: 24874
diff changeset
5461 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
5462 || 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
5463 || cctx->ctx_ufunc->uf_ret_type == &t_any))
24890
0cba2be8cbd7 patch 8.2.2983: Vim9: an inline function requires specifying the return type
Bram Moolenaar <Bram@vim.org>
parents: 24874
diff changeset
5464 || (!check_return_type
0cba2be8cbd7 patch 8.2.2983: Vim9: an inline function requires specifying the return type
Bram Moolenaar <Bram@vim.org>
parents: 24874
diff changeset
5465 && cctx->ctx_ufunc->uf_ret_type == &t_unknown))
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
5466 {
22926
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5467 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
5468 }
22926
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5469 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
5470 {
22926
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5471 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
5472 && 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
5473 && 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
5474 {
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5475 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
5476 return NULL;
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5477 }
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5478 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
5479 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
5480 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
5481 }
1a393685e7ce patch 8.2.1131: Vim9: error message for returning a value is not clear
Bram Moolenaar <Bram@vim.org>
parents: 21158
diff changeset
5482 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5483 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5484 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5485 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
5486 // "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
5487 // 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
5488 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
5489 && 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
5490 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5491 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
5492 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5493 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5494
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5495 // 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
5496 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
5497 }
23586
8c5374ec8a3d patch 8.2.2335: Vim9: "silent return" does not restore command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 23578
diff changeset
5498
8c5374ec8a3d patch 8.2.2335: Vim9: "silent return" does not restore command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 23578
diff changeset
5499 // 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
5500 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
5501
22926
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5502 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
5503 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5504
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5505 // "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
5506 return skipwhite(p);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5507 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5508
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5509 /*
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5510 * 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
5511 * 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
5512 * 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
5513 */
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5514 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
5515 exarg_getline(
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5516 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
5517 void *cookie,
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5518 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
5519 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
5520 {
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5521 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
5522 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
5523
a427f5f26419 patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents: 21881
diff changeset
5524 for (;;)
a427f5f26419 patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents: 21881
diff changeset
5525 {
22423
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22415
diff changeset
5526 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
5527 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
5528 ++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
5529 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
5530 // 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
5531 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
5532 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
5533 }
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5534 }
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5535
24188
c20e763bc73c patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents: 24158
diff changeset
5536 void
c20e763bc73c patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents: 24158
diff changeset
5537 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
5538 {
c20e763bc73c patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents: 24158
diff changeset
5539 eap->getline = exarg_getline;
c20e763bc73c patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents: 24158
diff changeset
5540 eap->cookie = cctx;
c20e763bc73c patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents: 24158
diff changeset
5541 }
c20e763bc73c patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents: 24158
diff changeset
5542
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5543 /*
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5544 * 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
5545 */
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5546 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
5547 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
5548 {
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5549 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
5550 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
5551 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
5552 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
5553 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
5554 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
5555
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
5556 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
5557 {
f9b4576a618b patch 8.2.1657: Vim9: no proper error for nested ":def!"
Bram Moolenaar <Bram@vim.org>
parents: 22196
diff changeset
5558 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
5559 return NULL;
f9b4576a618b patch 8.2.1657: Vim9: no proper error for nested ":def!"
Bram Moolenaar <Bram@vim.org>
parents: 22196
diff changeset
5560 }
f9b4576a618b patch 8.2.1657: Vim9: no proper error for nested ":def!"
Bram Moolenaar <Bram@vim.org>
parents: 22196
diff changeset
5561
22973
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5562 if (*name_start == '/')
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5563 {
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5564 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
5565 if (*name_end == '/')
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5566 ++name_end;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5567 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
5568 }
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5569 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
5570 {
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5571 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
5572 {
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5573 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
5574 return NULL;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5575 }
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5576
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5577 // "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
5578 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
5579 return NULL;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5580 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
5581 }
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5582
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
5583 // 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
5584 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
5585 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5586 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
5587 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
5588 }
24033
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
5589 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
5590 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
5591
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5592 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
5593 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
5594
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5595 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
5596 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
5597 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
5598 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
5599 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
5600
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20419
diff changeset
5601 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
5602 {
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
5603 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
5604 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
5605 }
24152
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5606
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5607 // 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
5608 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
5609 {
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5610 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
5611
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5612 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
5613 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
5614 {
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5615 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
5616 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
5617 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
5618 }
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5619 }
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5620
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
5621 if (func_needs_compiling(ufunc, COMPILE_TYPE(ufunc))
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
5622 && compile_def_function(ufunc, TRUE, COMPILE_TYPE(ufunc), cctx)
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
5623 == FAIL)
22369
62192fd08e0e patch 8.2.1733: Vim9: memory leaks when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
5624 {
62192fd08e0e patch 8.2.1733: Vim9: memory leaks when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
5625 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
5626 goto theend;
22369
62192fd08e0e patch 8.2.1733: Vim9: memory leaks when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
5627 }
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5628
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5629 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
5630 {
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5631 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
5632 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
5633
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5634 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
5635 r = FAIL;
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5636 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
5637 {
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
5638 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
5639 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
5640 }
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5641 }
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5642 else
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5643 {
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5644 // 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
5645 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
5646 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
5647
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
5648 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
5649 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
5650 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
5651 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
5652 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
5653 }
20305
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
5654 // 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
5655
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
5656 theend:
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
5657 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
5658 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
5659 }
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5660
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5661 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5662 * 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
5663 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5664 int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5665 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
5666 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5667 if (*p == '=')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5668 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5669 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
5670 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5671 *heredoc = TRUE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5672 return 3;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5673 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5674 return 1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5675 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5676 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
5677 return 2;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5678 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
5679 return 3;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5680 return 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5681 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5682
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5683 /*
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5684 * 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
5685 */
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5686 static void
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5687 generate_loadvar(
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5688 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
5689 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
5690 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
5691 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
5692 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
5693 {
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5694 switch (dest)
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5695 {
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5696 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
5697 // 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
5698 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
5699 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5700 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
5701 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
5702 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
5703 else
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
5704 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
5705 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5706 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
5707 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
5708 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5709 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
5710 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
5711 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5712 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
5713 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
5714 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5715 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
5716 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
5717 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
5718 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5719 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
5720 // 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
5721 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
5722 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5723 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
5724 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
5725 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5726 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
5727 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
5728 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5729 case dest_local:
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5730 if (lvar->lv_from_outer > 0)
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5731 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
5732 type);
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5733 else
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5734 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
5735 break;
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5736 case dest_expr:
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5737 // 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
5738 break;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5739 }
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5740 }
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5741
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5742 /*
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5743 * 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
5744 * 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
5745 */
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5746 static char_u *
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5747 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
5748 {
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5749 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
5750
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5751 if (*p == '[')
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5752 {
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5753 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
5754 (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
5755 p = skipwhite(p);
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5756 if (*p == ']')
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5757 return p + 1;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5758 return p;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5759 }
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5760 // if (*p == '.')
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5761 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
5762 }
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5763
20953
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5764 void
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5765 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
5766 {
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5767 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
5768
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5769 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
5770 {
20961
0e01976dfd3b patch 8.2.1032: error message for declaring a variable cannot be translated
Bram Moolenaar <Bram@vim.org>
parents: 20955
diff changeset
5771 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
5772 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
5773 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
5774 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
5775 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
5776 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
5777 return;
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5778 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
5779 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
5780 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
5781 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
5782 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
5783 }
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
5784 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
5785 }
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5786
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5787 /*
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5788 * 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
5789 * 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
5790 * 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
5791 * 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
5792 * "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
5793 * 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
5794 */
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5795 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
5796 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
5797 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
5798 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
5799 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
5800 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
5801 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
5802 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
5803 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
5804 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5805 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
5806
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5807 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
5808 {
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5809 int cc;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5810 long numval;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5811 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
5812
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5813 *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
5814 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
5815 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5816 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
5817 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
5818 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5819 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
5820 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
5821 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
5822 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5823 // 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
5824 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
5825 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
5826 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5827 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
5828 *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
5829 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
5830 &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
5831 *p = cc;
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5832 switch (opt_type)
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5833 {
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5834 case gov_unknown:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5835 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
5836 return FAIL;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5837 case gov_string:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5838 case gov_hidden_string:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5839 *type = &t_string;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5840 break;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5841 case gov_bool:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5842 case gov_hidden_bool:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5843 *type = &t_bool;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5844 break;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5845 case gov_number:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5846 case gov_hidden_number:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5847 *type = &t_number;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5848 break;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5849 }
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5850 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5851 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
5852 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5853 *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
5854 *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
5855 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5856 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
5857 {
25032
123590c942b7 patch 8.2.3053: Vim9: cannot assign to @@ in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25030
diff changeset
5858 if (name[1] != '@'
123590c942b7 patch 8.2.3053: Vim9: cannot assign to @@ in :def function
Bram Moolenaar <Bram@vim.org>
parents: 25030
diff changeset
5859 && (!valid_yank_reg(name[1], FALSE) || name[1] == '.'))
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5860 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5861 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
5862 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
5863 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5864 *dest = dest_reg;
24956
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24948
diff changeset
5865 *type = name[1] == '#' ? &t_number_or_string : &t_string;
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5866 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5867 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
5868 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5869 *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
5870 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5871 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
5872 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5873 *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
5874 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5875 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
5876 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5877 *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
5878 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5879 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
5880 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5881 *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
5882 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5883 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
5884 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5885 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
5886 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
5887
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5888 *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
5889 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
5890 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5891 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
5892 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
5893 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5894 // 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
5895 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
5896 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
5897 *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
5898 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
5899 *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
5900 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5901 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
5902 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5903
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5904 /*
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5905 * 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
5906 * 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
5907 */
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5908 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
5909 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
5910 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
5911 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
5912 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
5913 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
5914 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
5915 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
5916 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
5917 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
5918 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5919 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
5920 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5921 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
5922 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
5923 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
5924 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
5925 // 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
5926 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
5927 ? 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
5928 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
5929 // 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
5930 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
5931 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
5932 // 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
5933 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
5934 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
5935 // 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
5936 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
5937 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
5938 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
5939 case dest_reg:
24956
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24948
diff changeset
5940 return generate_STORE(cctx, ISN_STOREREG,
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24948
diff changeset
5941 name[1] == '@' ? '"' : name[1], NULL);
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5942 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
5943 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
5944 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
5945 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
5946 // "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
5947 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
5948 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
5949 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
5950 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
5951 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
5952 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
5953 // 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
5954 break;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5955 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5956 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
5957 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5958
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5959 static int
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5960 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
5961 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5962 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
5963 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
5964 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
5965 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
5966 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
5967
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5968 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
5969 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5970 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
5971 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
5972
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5973 // 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
5974 // ISN_STORENR
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5975 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
5976 && 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
5977 && 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
5978 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5979 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
5980 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
5981
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5982 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
5983 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
5984 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
5985 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
5986 --stack->ga_len;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5987 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5988 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
5989 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
5990 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
5991 else
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5992 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
5993 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5994 return OK;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5995 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5996
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5997 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
5998 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
5999 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6000 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
6001 || 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
6002 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6003
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6004 /*
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6005 * 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
6006 * 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
6007 * 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
6008 */
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6009 static int
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6010 compile_lhs(
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6011 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
6012 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
6013 int cmdidx,
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6014 int heredoc,
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6015 int oplen,
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6016 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
6017 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6018 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
6019 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
6020
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6021 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
6022 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
6023 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
6024 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
6025
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6026 // "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
6027 // ".name".
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6028 // "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
6029 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
6030 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
6031 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
6032 else
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 // 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
6035 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
6036 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
6037 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6038
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6039 // "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
6040 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
6041 && 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
6042 --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
6043 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
6044 --var_end;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6045
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6046 // 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
6047 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
6048 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
6049 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
6050 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
6051 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
6052
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
6053 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
6054 // 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
6055 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
6056
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6057 if (heredoc)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6058 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
6059 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6060 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
6061
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6062 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
6063 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6064 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
6065
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6066 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
6067 &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
6068 &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
6069 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
6070 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
6071 && 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
6072 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6073 // 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
6074 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
6075 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6076 else
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 // No specific kind of variable recognized, just a name.
24717
bf8feac8a89a patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24713
diff changeset
6079 if (check_reserved_name(lhs->lhs_name) == FAIL)
bf8feac8a89a patch 8.2.2897: Vim9: can use reserved words at the script level
Bram Moolenaar <Bram@vim.org>
parents: 24713
diff changeset
6080 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
6081
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6082 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
6083 &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
6084 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
6085 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6086 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6087 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
6088 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
6089 &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
6090 &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
6091 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6092 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
6093 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6094 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
6095 return FAIL;
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 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
6098 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6099 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6100 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
6101 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6102 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
6103 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6104 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
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 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6109 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6110 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
6111 && 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
6112 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
6113 ? 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
6114 cctx)
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6115 : 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
6116 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
6117 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
6118 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
6119
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6120 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
6121 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6122 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
6123 + (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
6124
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6125 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
6126 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6127 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
6128 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
6129 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
6130 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
6131 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
6132 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
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 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6135 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
6136 == 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
6137 && script_namespace
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6138 && !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
6139 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6140 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
6141 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6142 }
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 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
6145
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6146 // 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
6147 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
6148 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
6149 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
6150 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
6151 {
23578
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
6152 // 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
6153 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
6154 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
6155 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
6156 cctx);
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6157 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
6158 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6159 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
6160 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
6161 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
6162 ((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
6163 + 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
6164 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
6165 }
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 }
24033
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
6168 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
6169 == FAIL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6170 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6171 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6172 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6173
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6174 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
6175 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6176 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
6177 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6178 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6179 }
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 // 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
6182 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
6183 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
6184
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6185 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
6186 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6187 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
6188 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6189 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
6190
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6191 // 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
6192 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
6193 {
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
6194 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
6195 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6196 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6197 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
6198 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
6199 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
6200 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6201 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
6202 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6203 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
6204 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
6205 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6206
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
6207 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
6208 && 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
6209 && !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
6210 && 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
6211 && 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
6212 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6213 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
6214 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6215 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6216
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6217 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
6218 && 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
6219 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6220 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
6221 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6222 // +=, /=, 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
6223 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
6224 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6225 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6226 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
6227 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6228 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
6229 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6230 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6231
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
6232 // 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
6233 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
6234 || 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
6235 && 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
6236 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
6237
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
6238 // 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
6239 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
6240 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
6241 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
6242 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6243 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
6244 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6245
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6246 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
6247 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
6248 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6249 // 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
6250 // 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
6251 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
6252 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6253 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
6254 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6255 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6256
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6257 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
6258 || 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
6259 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6260 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
6261 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
6262
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6263 // 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
6264 // 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
6265 // "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
6266 for (;;)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6267 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6268 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
6269 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
6270 {
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
6271 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
6272 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
6273 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6274 after = p;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6275 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6276 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
6277 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6278 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
6279 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
6280 // 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
6281 // 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
6282 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
6283 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6284
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6285 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
6286 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
6287 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6288 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
6289 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6290 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6291 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6292 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
6293 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6294 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6295 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6296 return OK;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6297 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6298
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6299 /*
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6300 * 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
6301 */
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6302 static int
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6303 compile_assign_lhs(
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6304 char_u *var_start,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6305 lhs_T *lhs,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6306 int cmdidx,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6307 int is_decl,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6308 int heredoc,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6309 int oplen,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6310 cctx_T *cctx)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6311 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6312 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
6313 return FAIL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6314
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6315 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
6316 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6317 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
6318 return FAIL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6319 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6320 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
6321 && 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
6322 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6323 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
6324 return FAIL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6325 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6326 return OK;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6327 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6328
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6329 /*
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
6330 * 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
6331 * "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
6332 */
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
6333 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
6334 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
6335 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
6336 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
6337 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
6338 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
6339 {
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
6340 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
6341 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
6342 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
6343 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
6344 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
6345
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6346 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
6347 if (*p == '[')
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6348 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6349 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
6350 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
6351 {
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6352 // 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
6353 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
6354 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
6355 }
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6356 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
6357 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
6358
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6359 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
6360 {
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6361 // 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
6362 // 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
6363 *range = TRUE;
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6364 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
6365 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
6366 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
6367 || (!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
6368 {
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6369 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
6370 ":", p);
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6371 return FAIL;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6372 }
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6373 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
6374 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
6375 // 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
6376 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
6377 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
6378 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
6379 }
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6380
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6381 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
6382 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6383 // 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
6384 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
6385 r = FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6386 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6387 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6388 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
6389 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6390 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
6391 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
6392
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6393 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
6394 }
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
6395 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
6396 }
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
6397
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
6398 /*
24363
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6399 * 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
6400 */
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6401 static int
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6402 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
6403 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
6404 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
6405 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
6406 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
6407 {
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6408 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
6409 {
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6410 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
6411 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
6412 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
6413 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
6414
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6415 // 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
6416 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
6417 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
6418 {
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6419 // 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
6420 emsg(_(e_missbrac));
24379
8d5e4b50c2e1 patch 8.2.2730: Coverity complains about not restoring character
Bram Moolenaar <Bram@vim.org>
parents: 24377
diff changeset
6421 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
6422 return FAIL;
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6423 }
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6424 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
6425
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6426 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
6427 : ((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
6428 // 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
6429 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
6430 && 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
6431 && 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
6432 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
6433 return FAIL;
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6434 }
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6435 else
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6436 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
6437 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
6438 return OK;
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6439 }
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6440
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6441 /*
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
6442 * 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
6443 * 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
6444 */
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
6445 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
6446 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
6447 {
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
6448 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
6449
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
6450 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
6451 {
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
6452 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
6453
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
6454 // 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
6455 // 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
6456 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
6457 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
6458 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
6459 {
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
6460 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
6461 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
6462 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
6463 }
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
6464
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
6465 // 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
6466 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
6467 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
6468 }
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
6469 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
6470 }
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
6471
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
6472 /*
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
6473 * 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
6474 * 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
6475 * 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
6476 */
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
6477 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
6478 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
6479 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
6480 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
6481 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
6482 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
6483 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
6484 {
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
6485 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
6486 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
6487 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
6488
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
6489 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
6490 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
6491 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
6492 && 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
6493 {
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6494 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
6495 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
6496 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6497
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6498 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
6499 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6500 // 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
6501 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
6502 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6503 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6504 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6505 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
6506 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
6507 {
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6508 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
6509 return FAIL;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6510 }
24796
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
6511 if (dest_type == VAR_DICT
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
6512 && may_generate_2STRING(-1, FALSE, cctx) == FAIL)
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6513 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
6514 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
6515 {
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6516 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
6517
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6518 if (range)
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6519 {
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6520 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
6521 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
6522 -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
6523 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
6524 }
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6525 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
6526 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
6527 && 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
6528 -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
6529 return FAIL;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6530 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6531 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6532
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6533 // 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
6534 // - 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
6535 // - index
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6536 // - 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
6537 // - variable
24363
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6538 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
6539 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
6540
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
6541 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
6542 || 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
6543 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6544 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
6545 {
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
6546 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
6547 {
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6548 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
6549 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
6550 }
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6551 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
6552 {
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6553 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
6554
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6555 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
6556 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
6557 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
6558 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6559 }
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6560 else if (range)
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6561 {
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6562 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
6563 return FAIL;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6564 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6565 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6566 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6567 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
6568 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6569 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6570 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6571 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6572 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6573 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
6574 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6575 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6576
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6577 return OK;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6578 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6579
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6580 /*
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6581 * Compile declaration and assignment:
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6582 * "let name"
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6583 * "var name = expr"
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6584 * "final name = expr"
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6585 * "const name = expr"
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6586 * "name = expr"
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6587 * "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
6588 * "++arg" and "--arg"
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6589 * 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
6590 * 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
6591 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6592 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6593 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
6594 {
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6595 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
6596 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
6597 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
6598 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
6599 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
6600 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
6601 int semicolon = 0;
25034
8d660d1cca8d patch 8.2.3054: Vim9: unpack assignment using "_" after semicolon fails
Bram Moolenaar <Bram@vim.org>
parents: 25032
diff changeset
6602 int did_generate_slice = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6603 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
6604 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
6605 char_u *op;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6606 int oplen = 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6607 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
6608 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
6609 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
6610 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
6611 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
6612 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
6613 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
6614
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6615 // 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
6616 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
6617 if (p == NULL)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6618 return *arg == '[' ? arg : NULL;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6619
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6620 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
6621 {
21421
0f0fee4122d3 patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents: 21411
diff changeset
6622 // 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
6623 // members?
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
6624 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
6625 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6626 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6627 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
6628
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6629 sp = p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6630 p = skipwhite(p);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6631 op = p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6632 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
6633
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6634 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
6635 // 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
6636 return arg;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6637
23052
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
6638 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
6639 {
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
6640 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
6641 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
6642 }
24533
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6643 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
6644 {
25022
39551b6e0112 patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents: 25004
diff changeset
6645 if (VIM_ISWHITE(eap->cmd[2]))
39551b6e0112 patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents: 25004
diff changeset
6646 {
39551b6e0112 patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents: 25004
diff changeset
6647 semsg(_(e_no_white_space_allowed_after_str_str),
39551b6e0112 patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents: 25004
diff changeset
6648 eap->cmdidx == CMD_increment ? "++" : "--", eap->cmd);
39551b6e0112 patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents: 25004
diff changeset
6649 return NULL;
39551b6e0112 patch 8.2.3048: strange error for white space after ++ command
Bram Moolenaar <Bram@vim.org>
parents: 25004
diff changeset
6650 }
24533
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6651 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
6652 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
6653 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
6654 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6655
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6656 if (heredoc)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6657 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6658 list_T *l;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6659 listitem_T *li;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6660
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6661 // [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
6662 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
6663 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
6664 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
6665 if (l == NULL)
66d1131a7eff patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
6666 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6667
22343
9f5a84baa464 patch 8.2.1720: Vim9: memory leak with heredoc that isn't executed
Bram Moolenaar <Bram@vim.org>
parents: 22341
diff changeset
6668 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
6669 {
22343
9f5a84baa464 patch 8.2.1720: Vim9: memory leak with heredoc that isn't executed
Bram Moolenaar <Bram@vim.org>
parents: 22341
diff changeset
6670 // 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
6671 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
6672 {
9f5a84baa464 patch 8.2.1720: Vim9: memory leak with heredoc that isn't executed
Bram Moolenaar <Bram@vim.org>
parents: 22341
diff changeset
6673 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
6674 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
6675 }
9f5a84baa464 patch 8.2.1720: Vim9: memory leak with heredoc that isn't executed
Bram Moolenaar <Bram@vim.org>
parents: 22341
diff changeset
6676 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
6677 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6678 list_free(l);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6679 p += STRLEN(p);
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6680 end = p;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6681 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6682 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
6683 {
23052
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
6684 char_u *wp;
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
6685
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6686 // 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
6687 // 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
6688 // 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
6689
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
6690 wp = op + oplen;
23122
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23114
diff changeset
6691 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
6692 return FAIL;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6693 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
6694 return NULL;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6695 end = p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6696
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
6697 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
6698 {
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6699 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
6700
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19934
diff changeset
6701 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
6702 : ((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
6703 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
6704 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
6705 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
6706 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6707 }
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
6708 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
6709 FALSE, FALSE) == FAIL)
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6710 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
6711 // 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
6712 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
6713 semicolon);
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6714 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
6715 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
6716 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6717 }
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 /*
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6720 * 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
6721 * 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
6722 */
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6723 if (var_count > 0)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6724 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
6725 else
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6726 var_start = arg;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6727 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
6728 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6729 int instr_count = -1;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6730
24426
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6731 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
6732 {
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6733 // 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
6734 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
6735 {
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6736 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
6737 continue;
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6738 }
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6739 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
6740 goto theend;
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6741 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6742 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
6743
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6744 /*
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6745 * 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
6746 */
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6747 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
6748 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
6749 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6750 if (!heredoc)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6751 {
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
6752 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
6753 {
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6754 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
6755 {
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6756 // 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
6757 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
6758 (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
6759 }
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6760 }
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6761 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
6762 {
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
6763 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
6764 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
6765
24984
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
6766 // for "+=", "*=", "..=" etc. first load the current value
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
6767 if (*op != '='
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
6768 && compile_load_lhs_with_index(&lhs, var_start,
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
6769 cctx) == FAIL)
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
6770 goto theend;
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
6771
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6772 // 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
6773 if (var_count == 0)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6774 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6775 int r;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6776
24533
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6777 // Compile the expression.
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6778 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
6779 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
6780 {
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6781 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
6782 }
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6783 else
23082
2120e4b40e12 patch 8.2.2087: Vim9: memory leak when statement is truncated
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
6784 {
24533
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6785 // 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
6786 // 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
6787 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
6788 --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
6789 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
6790 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
6791 {
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6792 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
6793 ++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
6794 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
6795 }
9c404d78d767 patch 8.2.2806: Vim9: using "++nr" as a command might not work
Bram Moolenaar <Bram@vim.org>
parents: 24531
diff changeset
6796 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
6797 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
6798 ++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
6799 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
6800 goto theend;
23082
2120e4b40e12 patch 8.2.2087: Vim9: memory leak when statement is truncated
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
6801 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6802 }
20871
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
6803 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
6804 {
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
6805 // For "[var; var] = expr" get the rest of the list
25034
8d660d1cca8d patch 8.2.3054: Vim9: unpack assignment using "_" after semicolon fails
Bram Moolenaar <Bram@vim.org>
parents: 25032
diff changeset
6806 did_generate_slice = TRUE;
20871
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
6807 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
6808 goto theend;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
6809 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6810 else
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6811 {
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6812 // 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
6813 // list.
24984
71b1e2ef0069 patch 8.2.3029: Vim9: crash when using operator and list unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 24956
diff changeset
6814 if (generate_GETITEM(cctx, var_idx, *op != '=') == FAIL)
23070
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23068
diff changeset
6815 goto theend;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6816 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6817
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6818 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
6819 : ((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
6820 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
6821 {
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6822 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
6823 || 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
6824 && !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
6825 && 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
6826 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
6827
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6828 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
6829 {
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6830 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
6831 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
6832 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
6833 goto theend;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6834 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6835 else
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6836 {
22363
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22343
diff changeset
6837 // 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
6838 // 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
6839 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
6840 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
6841 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
6842 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
6843 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
6844 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
6845 else
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6846 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
6847 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6848 }
21881
675bf9475fff patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
6849 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
6850 {
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6851 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
6852
24329
cd9f77409393 patch 8.2.2705: Vim9: misleading reported line number for wrong type
Bram Moolenaar <Bram@vim.org>
parents: 24295
diff changeset
6853 // 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
6854 // 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
6855 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
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 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
6858 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
6859 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
6860 goto theend;
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6861 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6862 }
24956
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24948
diff changeset
6863 else
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24948
diff changeset
6864 {
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24948
diff changeset
6865 type_T *lhs_type = lhs.lhs_member_type;
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24948
diff changeset
6866
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24948
diff changeset
6867 // Special case: assigning to @# can use a number or a
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24948
diff changeset
6868 // string.
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24948
diff changeset
6869 if (lhs_type == &t_number_or_string
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24948
diff changeset
6870 && rhs_type->tt_type == VAR_NUMBER)
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24948
diff changeset
6871 lhs_type = &t_number;
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24948
diff changeset
6872 if (*p != '=' && need_type(rhs_type, lhs_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
6873 -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
6874 goto theend;
24956
d0b6a8d82cef patch 8.2.3015: Vim9: Assigning to @# requires a string
Bram Moolenaar <Bram@vim.org>
parents: 24948
diff changeset
6875 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6876 }
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6877 else if (cmdidx == CMD_final)
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6878 {
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6879 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
6880 goto theend;
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6881 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6882 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
6883 {
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
6884 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
6885 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6886 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6887 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
6888 {
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
6889 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
6890 goto theend;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6891 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6892 else
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6893 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6894 // variables are always initialized
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6895 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
6896 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
6897 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
6898 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6899 case VAR_BOOL:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6900 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
6901 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6902 case VAR_FLOAT:
19336
1cd6eab65ce0 patch 8.2.0226: compiling for loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
6903 #ifdef FEAT_FLOAT
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6904 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
6905 #endif
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6906 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6907 case VAR_STRING:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6908 generate_PUSHS(cctx, NULL);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6909 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6910 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
6911 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
6912 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6913 case VAR_FUNC:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6914 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
6915 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6916 case VAR_LIST:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6917 generate_NEWLIST(cctx, 0);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6918 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6919 case VAR_DICT:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6920 generate_NEWDICT(cctx, 0);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6921 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6922 case VAR_JOB:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6923 generate_PUSHJOB(cctx, NULL);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6924 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6925 case VAR_CHANNEL:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6926 generate_PUSHCHANNEL(cctx, NULL);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6927 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6928 case VAR_NUMBER:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6929 case VAR_UNKNOWN:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6930 case VAR_ANY:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6931 case VAR_PARTIAL:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6932 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
6933 case VAR_INSTR:
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6934 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
6935 generate_PUSHNR(cctx, 0);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6936 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6937 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6938 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6939 if (var_count == 0)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6940 end = p;
19336
1cd6eab65ce0 patch 8.2.0226: compiling for loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
6941 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6942
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6943 // 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
6944 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
6945 break;
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6946
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6947 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
6948 {
21881
675bf9475fff patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
6949 type_T *expected;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6950 type_T *stacktype;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6951
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6952 if (*op == '.')
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6953 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
6954 else
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6955 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
6956 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
6957 if (
675bf9475fff patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
6958 #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
6959 // 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
6960 !(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
6961 #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
6962 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
6963 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
6964 goto theend;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6965
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6966 if (*op == '.')
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
6967 {
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
6968 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
6969 goto theend;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
6970 }
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
6971 else if (*op == '+')
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
6972 {
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
6973 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
6974 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
6975 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
6976 goto theend;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
6977 }
21881
675bf9475fff patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
6978 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
6979 goto theend;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6980 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6981
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6982 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
6983 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6984 // 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
6985 // 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
6986 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
6987 == FAIL)
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6988 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
6989 }
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6990 else
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6991 {
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6992 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
6993 || 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
6994 || 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
6995 // ":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
6996 generate_LOCKCONST(cctx);
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
6997
23458
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
6998 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
6999 && (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
7000 || 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
7001 && 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
7002 && 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
7003 && 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
7004 // 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
7005 // 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
7006 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
7007
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
7008 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
7009 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
7010 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
7011
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
7012 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
7013 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
7014 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
7015
25034
8d660d1cca8d patch 8.2.3054: Vim9: unpack assignment using "_" after semicolon fails
Bram Moolenaar <Bram@vim.org>
parents: 25032
diff changeset
7016 // For "[var, var] = expr" drop the "expr" value.
8d660d1cca8d patch 8.2.3054: Vim9: unpack assignment using "_" after semicolon fails
Bram Moolenaar <Bram@vim.org>
parents: 25032
diff changeset
7017 // Also for "[var, var; _] = expr".
8d660d1cca8d patch 8.2.3054: Vim9: unpack assignment using "_" after semicolon fails
Bram Moolenaar <Bram@vim.org>
parents: 25032
diff changeset
7018 if (var_count > 0 && (!semicolon || !did_generate_slice))
20871
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
7019 {
23195
75f35ae990ac patch 8.2.2143: Vim9: dead code in compiling :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23187
diff changeset
7020 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
7021 goto theend;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
7022 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
7023
21391
8b882afa8ed2 patch 8.2.1246: Vim9: comment after assignment doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21387
diff changeset
7024 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
7025
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7026 theend:
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7027 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
7028 return ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7029 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7030
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7031 /*
23537
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
7032 * 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
7033 * 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
7034 */
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
7035 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
7036 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
7037 {
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
7038 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
7039 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
7040
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
7041 // 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
7042 // 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
7043 // 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
7044 // 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
7045 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
7046 ? 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
7047 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
7048 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
7049 {
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
7050 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
7051 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
7052 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
7053
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
7054 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
7055 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
7056 else
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
7057 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
7058 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
7059 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
7060 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
7061 {
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
7062 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
7063
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
7064 // 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
7065 // name:
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
7066 // "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
7067 // "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
7068 // "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
7069 // "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
7070 // "&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
7071 // "$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
7072 // "@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
7073 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
7074 || *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
7075 || *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
7076 || ((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
7077 || 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
7078 {
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
7079 *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
7080 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
7081 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
7082 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
7083 }
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
7084 }
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
7085 }
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
7086
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
7087 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
7088 {
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
7089 // [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
7090 *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
7091 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
7092 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
7093 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
7094 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
7095 }
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
7096 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
7097 }
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
7098
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
7099 /*
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7100 * 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
7101 */
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7102 int
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7103 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
7104 {
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7105 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
7106 {
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
7107 // "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
7108 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
7109 return OK;
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
7110 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
7111 return FAIL;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7112 }
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7113 return OK;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7114 }
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7115
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7116 /*
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7117 * Callback passed to ex_unletlock().
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7118 */
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7119 static int
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7120 compile_unlet(
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7121 lval_T *lvp,
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7122 char_u *name_end,
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7123 exarg_T *eap,
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7124 int deep UNUSED,
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7125 void *coookie)
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7126 {
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7127 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
7128 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
7129 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
7130 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
7131
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7132 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
7133 return OK;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7134
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7135 *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
7136 if (*p == '$')
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7137 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7138 // :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
7139 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
7140 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7141 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
7142 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7143 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
7144
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7145 // 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
7146 // 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
7147 // 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
7148 // 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
7149 //
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7150 // 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
7151 //
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7152 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
7153
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7154 // : 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
7155 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
7156 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7157 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
7158 ret = FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7159 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7160 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7161 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7162 // 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
7163 // 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
7164 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
7165 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7166
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7167 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
7168 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7169 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
7170 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7171 ret = FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7172 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7173 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7174 {
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7175 // 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
7176 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
7177 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7178
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
7179 *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
7180 return ret;
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7181 }
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7182
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7183 /*
24262
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7184 * 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
7185 */
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7186 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
7187 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
7188 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
7189 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
7190 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
7191 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
7192 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
7193 {
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7194 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
7195 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
7196 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
7197 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
7198 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
7199 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
7200
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7201 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
7202 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
7203
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7204 // 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
7205 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
7206 {
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7207 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
7208
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7209 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
7210 {
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7211 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
7212 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
7213 }
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7214 }
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7215
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7216 // 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
7217 *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
7218 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
7219 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
7220 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
7221 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
7222 else
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7223 {
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7224 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
7225 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
7226 p);
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7227 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
7228
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7229 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
7230 *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
7231 }
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7232 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
7233 }
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7234
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7235 /*
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7236 * 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
7237 * "arg" points to "var".
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7238 */
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7239 static char_u *
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7240 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
7241 {
24262
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
7242 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
7243 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
7244 cctx);
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7245 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
7246 }
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7247
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7248 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7249 * 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
7250 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7251 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7252 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
7253 {
21146
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
7254 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
7255 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7256
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 * 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
7259 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7260 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7261 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
7262 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7263 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
7264 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
7265
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7266 if (endlabel == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7267 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7268 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
7269 *el = endlabel;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7270 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
7271
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7272 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
7273 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7274 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7275
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7276 static void
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
7277 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
7278 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7279 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
7280
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7281 while (*el != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7282 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7283 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
7284 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7285
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7286 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
7287 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
7288 *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
7289 vim_free(cur);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7290 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7291 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7292
19896
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7293 static void
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7294 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
7295 {
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7296 while (*el != NULL)
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7297 {
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7298 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
7299
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7300 *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
7301 vim_free(cur);
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7302 }
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7303 }
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7304
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7305 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7306 * 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
7307 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7308 static scope_T *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7309 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
7310 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7311 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
7312
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7313 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7314 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7315 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
7316 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
7317 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
7318 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
7319 return scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7320 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7321
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7322 /*
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7323 * 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
7324 */
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7325 static void
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7326 drop_scope(cctx_T *cctx)
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7327 {
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7328 scope_T *scope = cctx->ctx_scope;
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7329
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7330 if (scope == NULL)
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7331 {
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7332 iemsg("calling drop_scope() without a scope");
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7333 return;
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7334 }
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7335 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
7336 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
7337 {
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7338 case IF_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7339 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
7340 case FOR_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7341 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
7342 case WHILE_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7343 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
7344 case TRY_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7345 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
7346 case NO_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7347 case BLOCK_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7348 break;
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7349 }
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7350 vim_free(scope);
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7351 }
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7352
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7353 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7354 * compile "if expr"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7355 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7356 * "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
7357 * 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
7358 * 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
7359 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7360 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7361 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7362 * "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
7363 * 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
7364 * 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
7365 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7366 * JUMP_ALWAYS end
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7367 * else:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7368 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7369 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7370 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7371 * "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
7372 * 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
7373 * 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
7374 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7375 * JUMP_ALWAYS end
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7376 * elseif:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7377 * 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
7378 * 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
7379 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7380 * JUMP_ALWAYS end
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7381 * else:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7382 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7383 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7384 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7385 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7386 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
7387 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7388 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
7389 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
7390 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
7391 scope_T *scope;
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7392 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
7393 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
7394
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
7395 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
7396 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
7397 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
7398 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
7399 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
7400 }
23882
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7401 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
7402 {
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7403 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
7404 return NULL;
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7405 }
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7406 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
7407 clear_ppconst(&ppconst);
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7408 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
7409 {
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7410 int error = FALSE;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7411 int v;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7412
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
7413 // 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
7414 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
7415 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
7416 if (error)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7417 return NULL;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7418 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
7419 }
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7420 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
7421 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
7422 // 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
7423 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
7424 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
7425 return NULL;
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7426 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
7427 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
7428 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7429
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7430 // 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
7431 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
7432
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7433 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
7434 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7435 return NULL;
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7436 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
7437 // "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
7438 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
7439
20933
e2fd5f05342f patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents: 20929
diff changeset
7440 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
7441 {
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7442 // "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
7443 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
7444 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
7445 }
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7446 else
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7447 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
7448
23723
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7449 #ifdef FEAT_PROFILE
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
7450 if (cctx->ctx_compile_type == CT_PROFILE && 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
7451 && 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
7452 {
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7453 // 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
7454 // 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
7455 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
7456 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
7457 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
7458 }
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7459 #endif
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7460
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7461 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7462 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7463
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7464 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7465 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
7466 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7467 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
7468 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
7469 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
7470 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7471 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
7472 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
7473 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
7474
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7475 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
7476 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7477 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
7478 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7479 }
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
7480 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
7481 if (!cctx->ctx_had_return)
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7482 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
7483
23723
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7484 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
7485 {
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7486 // 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
7487 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
7488 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
7489 }
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7490 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
7491 {
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7492 // 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
7493 // 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
7494 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
7495
23723
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7496 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
7497 return p;
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7498 }
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7499
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)
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7501 {
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7502 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
7503
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7504 // 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
7505 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
7506 {
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7507 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
7508 return NULL;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7509 ((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
7510 ((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
7511 --instr->ga_len;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7512 moved_cmdmod = TRUE;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7513 }
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7514
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7515 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
7516 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
7517 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
7518 // 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
7519 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
7520 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
7521 if (moved_cmdmod)
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7522 ++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
7523 }
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7524
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7525 // 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
7526 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
7527 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
7528 {
21959
67d4be2757b0 patch 8.2.1529: Vim9: :elseif may be compiled when not needed
Bram Moolenaar <Bram@vim.org>
parents: 21957
diff changeset
7529 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
7530 #ifdef FEAT_PROFILE
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
7531 if (cctx->ctx_compile_type == CT_PROFILE)
23723
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7532 {
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7533 // 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
7534 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
7535 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
7536 }
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7537 #endif
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
7538 if (cctx->ctx_compile_type == CT_DEBUG)
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
7539 {
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
7540 // the previous block was skipped, may want to debug this line
24918
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
7541 generate_instr_debug(cctx);
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
7542 instr_count = instr->ga_len;
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
7543 }
23723
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7544 }
20334
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7545 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
7546 {
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7547 clear_ppconst(&ppconst);
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7548 return NULL;
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7549 }
21959
67d4be2757b0 patch 8.2.1529: Vim9: :elseif may be compiled when not needed
Bram Moolenaar <Bram@vim.org>
parents: 21957
diff changeset
7550 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
7551 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
7552 {
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7553 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
7554 return NULL;
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7555 }
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7556 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
7557 clear_ppconst(&ppconst);
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7558 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
7559 {
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7560 int error = FALSE;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7561 int v;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7562
20334
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7563 // 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
7564 // 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
7565 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
7566 if (error)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7567 return NULL;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7568 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
7569 clear_ppconst(&ppconst);
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7570 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
7571 }
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7572 else
20334
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7573 {
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7574 // 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
7575 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
7576 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
7577 return NULL;
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7578 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
7579 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
7580
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7581 // 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
7582 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
7583
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7584 // "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
7585 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
7586 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
7587 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7588
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7589 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7590 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7591
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7592 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7593 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
7594 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7595 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
7596 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
7597 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7598 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
7599
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7600 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
7601 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7602 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
7603 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7604 }
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
7605 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
7606 if (!cctx->ctx_had_return)
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7607 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
7608 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
7609
23723
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7610 #ifdef FEAT_PROFILE
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
7611 if (cctx->ctx_compile_type == CT_PROFILE)
23723
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7612 {
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7613 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
7614 && ((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
7615 .isn_type == ISN_PROF_START)
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
7616 // the previous block was executed, do not count "else" for
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
7617 // profiling
23723
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7618 --instr->ga_len;
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7619 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
7620 {
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7621 // 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
7622 // "else" for profiling
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7623 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
7624 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
7625 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
7626 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
7627 }
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7628 }
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7629 #endif
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7630
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7631 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
7632 {
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7633 // 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
7634 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
7635 {
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7636 if (!cctx->ctx_had_return
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7637 && 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
7638 JUMP_ALWAYS, cctx) == FAIL)
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7639 return NULL;
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7640 }
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7641
20933
e2fd5f05342f patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents: 20929
diff changeset
7642 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
7643 {
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7644 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
7645 {
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7646 // 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
7647 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
7648 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
7649 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
7650 }
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7651 }
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7652
20933
e2fd5f05342f patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents: 20929
diff changeset
7653 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
7654 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
7655 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7656
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7657 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7658 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7659
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7660 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7661 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
7662 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7663 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
7664 ifscope_T *ifscope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7665 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
7666 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7667
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
7668 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
7669 return NULL;
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
7670
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7671 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
7672 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7673 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
7674 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7675 }
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
7676 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
7677 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
7678 if (!cctx->ctx_had_return)
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7679 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
7680
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7681 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
7682 {
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7683 // 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
7684 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
7685 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
7686 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7687 // 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
7688 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
7689
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7690 #ifdef FEAT_PROFILE
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7691 // 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
7692 // in is skipped
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
7693 if (cctx->ctx_compile_type == CT_PROFILE && 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
7694 && 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
7695 {
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7696 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
7697 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
7698 }
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7699 #endif
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7700 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
7701
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7702 // 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
7703 // had_return flag is set.
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7704 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
7705
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7706 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
7707 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7708 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7709
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7710 /*
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7711 * 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
7712 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7713 * Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7714 * PUSHNR -1
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7715 * 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
7716 * 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
7717 * 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
7718 * - 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
7719 * - 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
7720 * 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
7721 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7722 * 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
7723 * 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
7724 *
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7725 * 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
7726 * 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
7727 * 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
7728 * 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
7729 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7730 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
7731 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
7732 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7733 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
7734 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
7735 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
7736 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
7737 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
7738 int var_count = 0;
25028
faa3de7aed8b patch 8.2.3051: Vim9: for loop with one list variable does not work
Bram Moolenaar <Bram@vim.org>
parents: 25022
diff changeset
7739 int var_list = 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
7740 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
7741 size_t varlen;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7742 garray_T *stack = &cctx->ctx_type_stack;
24948
5c418c774f95 patch 8.2.3011: Vim9: cannot get argument values during debugging
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
7743 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
7744 scope_T *scope;
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
7745 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
7746 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
7747 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
7748 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
7749 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
7750
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7751 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
7752 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
7753 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
7754 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
7755 var_count = 1;
25028
faa3de7aed8b patch 8.2.3051: Vim9: for loop with one list variable does not work
Bram Moolenaar <Bram@vim.org>
parents: 25022
diff changeset
7756 else
faa3de7aed8b patch 8.2.3051: Vim9: for loop with one list variable does not work
Bram Moolenaar <Bram@vim.org>
parents: 25022
diff changeset
7757 var_list = TRUE; // can also be a list of one variable
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7758
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7759 // 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
7760 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
7761 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
7762 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
7763 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
7764 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7765 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
7766 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7767 }
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
7768 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
7769 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
7770 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7771
24948
5c418c774f95 patch 8.2.3011: Vim9: cannot get argument values during debugging
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
7772 // Remove the already generated ISN_DEBUG, it is written below the ISN_FOR
5c418c774f95 patch 8.2.3011: Vim9: cannot get argument values during debugging
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
7773 // instruction.
5c418c774f95 patch 8.2.3011: Vim9: cannot get argument values during debugging
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
7774 if (cctx->ctx_compile_type == CT_DEBUG && instr->ga_len > 0
5c418c774f95 patch 8.2.3011: Vim9: cannot get argument values during debugging
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
7775 && ((isn_T *)instr->ga_data)[instr->ga_len - 1]
5c418c774f95 patch 8.2.3011: Vim9: cannot get argument values during debugging
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
7776 .isn_type == ISN_DEBUG)
5c418c774f95 patch 8.2.3011: Vim9: cannot get argument values during debugging
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
7777 --instr->ga_len;
5c418c774f95 patch 8.2.3011: Vim9: cannot get argument values during debugging
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
7778
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7779 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
7780 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7781 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7782
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7783 // 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
7784 // to -1.
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
7785 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
7786 if (loop_lvar == NULL)
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
7787 {
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
7788 // out of memory
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7789 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
7790 return NULL;
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7791 }
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
7792 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
7793
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7794 // 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
7795 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
7796 if (compile_expr0(&arg, cctx) == FAIL)
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7797 {
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7798 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
7799 return NULL;
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7800 }
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7801 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
7802
24480
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
7803 // 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
7804 // 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
7805 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
7806 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
7807 && 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
7808 {
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
7809 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
7810 vartype_name(vartype->tt_type));
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7811 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
7812 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7813 }
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7814
24460
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7815 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
7816 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
7817 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
7818 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
7819 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
7820 && 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
7821 {
25028
faa3de7aed8b patch 8.2.3051: Vim9: for loop with one list variable does not work
Bram Moolenaar <Bram@vim.org>
parents: 25022
diff changeset
7822 if (!var_list)
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7823 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
7824 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
7825 && 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
7826 // 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
7827 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
7828 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7829
24948
5c418c774f95 patch 8.2.3011: Vim9: cannot get argument values during debugging
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
7830 // CMDMOD_REV must come before the FOR instruction.
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7831 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
7832
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7833 // "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
7834 scope->se_u.se_for.fs_top_label = current_instr_idx(cctx);
24948
5c418c774f95 patch 8.2.3011: Vim9: cannot get argument values during debugging
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
7835
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
7836 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
7837
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7838 arg = arg_start;
25028
faa3de7aed8b patch 8.2.3051: Vim9: for loop with one list variable does not work
Bram Moolenaar <Bram@vim.org>
parents: 25022
diff changeset
7839 if (var_list)
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7840 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7841 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
7842 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
7843
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7844 // 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
7845 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
7846 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7847 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
7848 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
7849 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7850 --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
7851 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
7852 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7853 ((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
7854 (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
7855 ++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
7856 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7857 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7858
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7859 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
7860 {
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7861 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
7862 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
7863 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
7864 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
7865 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
7866 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
7867
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7868 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
7869 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
7870 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
7871 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
7872 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
7873 if (*p == ':')
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7874 {
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7875 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
7876 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
7877 }
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7878
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7879 // 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
7880 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
7881 &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
7882 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
7883 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
7884 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7885 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
7886 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
7887 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
7888 }
24679
80422f66978a patch 8.2.2878: Vim9: for loop list unpack only allows for one "_"
Bram Moolenaar <Bram@vim.org>
parents: 24665
diff changeset
7889 else if (varlen == 1 && *arg == '_')
80422f66978a patch 8.2.2878: Vim9: for loop list unpack only allows for one "_"
Bram Moolenaar <Bram@vim.org>
parents: 24665
diff changeset
7890 {
80422f66978a patch 8.2.2878: Vim9: for loop list unpack only allows for one "_"
Bram Moolenaar <Bram@vim.org>
parents: 24665
diff changeset
7891 // Assigning to "_": drop the value.
80422f66978a patch 8.2.2878: Vim9: for loop list unpack only allows for one "_"
Bram Moolenaar <Bram@vim.org>
parents: 24665
diff changeset
7892 if (generate_instr_drop(cctx, ISN_DROP, 1) == NULL)
80422f66978a patch 8.2.2878: Vim9: for loop list unpack only allows for one "_"
Bram Moolenaar <Bram@vim.org>
parents: 24665
diff changeset
7893 goto failed;
80422f66978a patch 8.2.2878: Vim9: for loop list unpack only allows for one "_"
Bram Moolenaar <Bram@vim.org>
parents: 24665
diff changeset
7894 }
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7895 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
7896 {
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
7897 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
7898 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7899 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
7900 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
7901 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7902
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
7903 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
7904 {
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
7905 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
7906 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
7907 }
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
7908
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7909 // Reserve a variable to store "var".
25028
faa3de7aed8b patch 8.2.3051: Vim9: for loop with one list variable does not work
Bram Moolenaar <Bram@vim.org>
parents: 25022
diff changeset
7910 where.wt_index = var_list ? idx + 1 : 0;
24460
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7911 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
7912 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
7913 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
7914 else if (item_type != &t_unknown
25028
faa3de7aed8b patch 8.2.3051: Vim9: for loop with one list variable does not work
Bram Moolenaar <Bram@vim.org>
parents: 25022
diff changeset
7915 && !(var_list && item_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
7916 && 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
7917 goto failed;
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7918 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
7919 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
7920 // 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
7921 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
7922
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7923 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
7924 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
7925 else
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7926 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
7927 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
7928 }
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7929
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7930 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
7931 ++p;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7932 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
7933 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
7934 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7935
24948
5c418c774f95 patch 8.2.3011: Vim9: cannot get argument values during debugging
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
7936 if (cctx->ctx_compile_type == CT_DEBUG)
5c418c774f95 patch 8.2.3011: Vim9: cannot get argument values during debugging
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
7937 // Add ISN_DEBUG here, so that the loop variables can be inspected.
5c418c774f95 patch 8.2.3011: Vim9: cannot get argument values during debugging
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
7938 generate_instr_debug(cctx);
5c418c774f95 patch 8.2.3011: Vim9: cannot get argument values during debugging
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
7939
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7940 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
7941
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7942 failed:
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7943 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
7944 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
7945 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7946 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7947
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 * compile "endfor"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7950 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7951 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7952 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
7953 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7954 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
7955 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
7956 forscope_T *forscope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7957 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7958
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
7959 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
7960 return NULL;
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7961
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7962 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
7963 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7964 emsg(_(e_for));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7965 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7966 }
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
7967 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
7968 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
7969 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
7970
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7971 // 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
7972 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
7973
24948
5c418c774f95 patch 8.2.3011: Vim9: cannot get argument values during debugging
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
7974 // Fill in the "end" label in the FOR statement so it can jump here.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7975 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
7976 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
7977
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7978 // 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
7979 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
7980
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7981 // 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
7982 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
7983 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7984
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7985 vim_free(scope);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7986
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7987 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7988 }
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7991 * compile "while expr"
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 * Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7994 * 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
7995 * 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
7996 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7997 * 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
7998 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7999 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8000 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8001 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8002 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
8003 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8004 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
8005 scope_T *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 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
8008 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8009 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8010
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
8011 // "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
8012 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
8013
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8014 // 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
8015 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
8016 return NULL;
23882
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
8017 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
8018 {
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
8019 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
8020 return NULL;
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
8021 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8022
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
8023 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
8024 return FAIL;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
8025
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
8026 // 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
8027 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
8028
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8029 // "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
8030 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
8031 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
8032 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8033
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8034 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8035 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8036
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8037 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8038 * compile "endwhile"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8039 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8040 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8041 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
8042 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8043 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
8044 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
8045
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8046 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
8047 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8048 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
8049 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8050 emsg(_(e_while));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8051 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8052 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8053 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
8054 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
8055
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
8056 #ifdef FEAT_PROFILE
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8057 // 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
8058 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
8059 #endif
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8060
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8061 // 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
8062 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
8063
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8064 // 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
8065 // 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
8066 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
8067 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
8068
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8069 vim_free(scope);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8070
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8071 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8072 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8073
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8074 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8075 * compile "continue"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8076 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8077 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8078 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
8079 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8080 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
8081 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
8082 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
8083
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8084 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8085 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8086 if (scope == NULL)
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 emsg(_(e_continue));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8089 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8090 }
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
8091 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
8092 {
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
8093 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
8094 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
8095 }
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
8096 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
8097 {
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
8098 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
8099 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
8100 }
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
8101 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
8102 ++try_scopes;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8103 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
8104 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8105
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
8106 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
8107 // 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
8108 // "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
8109 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
8110 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
8111 // 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
8112 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
8113
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8114 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8115 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8116
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8117 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8118 * compile "break"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8119 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8120 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8121 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
8122 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8123 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
8124 endlabel_T **el;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8125
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8126 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8127 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8128 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8129 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8130 emsg(_(e_break));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8131 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8132 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8133 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
8134 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8135 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
8136 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8137
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8138 // 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
8139 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
8140 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
8141 else
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
8142 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
8143 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
8144 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8145
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8146 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8147 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8148
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8149 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8150 * 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
8151 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8152 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8153 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
8154 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8155 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
8156 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8157 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
8158 }
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8161 * 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
8162 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8163 static void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8164 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
8165 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8166 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
8167
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8168 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
8169 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
8170 vim_free(scope);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8171 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8172
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8173 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8174 * compile "try"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8175 * 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
8176 * finally.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8177 * 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
8178 * 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
8179 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8180 * "try"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8181 * 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
8182 * ... try block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8183 * "throw {exception}"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8184 * EVAL {exception}
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8185 * THROW create exception
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8186 * ... try block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8187 * " catch {expr}"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8188 * JUMP -> finally
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 23199
diff changeset
8189 * 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
8190 * EVAL {expr}
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8191 * MATCH
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8192 * JUMP nomatch -> catch2
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8193 * CATCH remove exception
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8194 * ... catch block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8195 * " catch"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8196 * JUMP -> finally
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8197 * 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
8198 * ... catch block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8199 * " finally"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8200 * finally:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8201 * ... finally block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8202 * " endtry"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8203 * 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
8204 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8205 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8206 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
8207 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8208 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
8209 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
8210 scope_T *scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8211
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8212 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
8213 return NULL;
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8214
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8215 // 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
8216 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
8217 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
8218 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8219
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8220 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
8221 {
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8222 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
8223
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8224 // "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
8225 // 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
8226 // "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
8227 // "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
8228 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
8229 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
8230 return NULL;
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8231 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
8232 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
8233 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
8234 }
19181
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 // 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
8237 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
8238 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8239 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8240
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8241 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8242 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8243
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8244 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8245 * compile "catch {expr}"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8246 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8247 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8248 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
8249 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8250 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
8251 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
8252 char_u *p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8253 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8254
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8255 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
8256 return NULL;
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8257
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8258 // 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
8259 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
8260 compile_endblock(cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8261 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
8262
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8263 // 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
8264 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
8265 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8266 emsg(_(e_catch));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8267 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8268 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8269
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
8270 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
8271 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
8272 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
8273 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8274 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8275
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8276 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
8277 {
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8278 #ifdef FEAT_PROFILE
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8279 // the profile-start should be after the jump
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
8280 if (cctx->ctx_compile_type == CT_PROFILE
24948
5c418c774f95 patch 8.2.3011: Vim9: cannot get argument values during debugging
Bram Moolenaar <Bram@vim.org>
parents: 24936
diff changeset
8281 && instr->ga_len > 0
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
8282 && ((isn_T *)instr->ga_data)[instr->ga_len - 1]
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8283 .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
8284 --instr->ga_len;
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8285 #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
8286 // 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
8287 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
8288 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
8289 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
8290
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8291 // 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
8292 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
8293 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
8294 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
8295 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
8296 {
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8297 // 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
8298 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
8299 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
8300 }
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8301 #ifdef FEAT_PROFILE
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
8302 if (cctx->ctx_compile_type == CT_PROFILE)
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8303 {
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8304 // 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
8305 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
8306 // 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
8307 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
8308 }
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8309 #endif
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
8310 if (cctx->ctx_compile_type == CT_DEBUG)
24918
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
8311 generate_instr_debug(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8312 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8313
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8314 p = skipwhite(arg);
20059
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20055
diff changeset
8315 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
8316 {
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
8317 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
8318 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
8319 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8320 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8321 {
19316
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8322 char_u *end;
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8323 char_u *pat;
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8324 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
8325 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
8326 int len;
19316
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8327
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8328 // 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
8329 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
8330
23505
bb29b09902d5 patch 8.2.2295: incsearch does not detect empty pattern properly
Bram Moolenaar <Bram@vim.org>
parents: 23497
diff changeset
8331 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
8332 if (*end != *p)
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8333 {
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
8334 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
8335 vim_free(tofree);
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8336 return FAIL;
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8337 }
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8338 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
8339 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
8340 else
19892
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19884
diff changeset
8341 len = (int)(end - tofree);
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19884
diff changeset
8342 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
8343 vim_free(tofree);
19892
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19884
diff changeset
8344 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
8345 if (pat == NULL)
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8346 return FAIL;
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8347 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
8348 return FAIL;
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8349
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8350 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
8351 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8352
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
8353 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
8354 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
8355 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8356 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8357
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8358 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
8359 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8360
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8361 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
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 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8364 }
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 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8367 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
8368 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8369 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
8370 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
8371 isn_T *isn;
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8372 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
8373
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8374 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
8375 return NULL;
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8376
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8377 // 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
8378 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
8379 compile_endblock(cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8380 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
8381
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8382 // 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
8383 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
8384 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8385 emsg(_(e_finally));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8386 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8387 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8388
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8389 // 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
8390 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
8391 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
8392 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8393 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
8394 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8395 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8396
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8397 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
8398 #ifdef FEAT_PROFILE
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
8399 if (cctx->ctx_compile_type == CT_PROFILE
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
8400 && ((isn_T *)instr->ga_data)[instr->ga_len - 1]
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8401 .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
8402 // 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
8403 --this_instr;
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8404 #endif
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8405
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8406 // 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
8407 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
8408 this_instr, cctx);
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8409
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8410 // 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
8411 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
8412 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
8413 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
8414 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
8415 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8416 // 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
8417 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
8418 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
8419 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
8420 }
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8421 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
8422 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8423
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8424 // 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
8425
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8426 return arg;
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 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8430 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
8431 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8432 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
8433 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
8434 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
8435
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8436 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
8437 return NULL;
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8438
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8439 // 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
8440 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
8441 compile_endblock(cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8442 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
8443
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8444 // 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
8445 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
8446 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8447 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8448 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
8449 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
8450 emsg(_(e_endwhile));
19213
b18437efabac patch 8.2.0165: Coverity warning for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents: 19193
diff changeset
8451 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
8452 emsg(_(e_endfor));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8453 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8454 emsg(_(e_endif));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8455 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8456 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8457
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
8458 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
8459 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
8460 {
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8461 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
8462 && 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
8463 {
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8464 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
8465 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
8466 }
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8467
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8468 #ifdef FEAT_PROFILE
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
8469 if (cctx->ctx_compile_type == CT_PROFILE
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
8470 && ((isn_T *)instr->ga_data)[instr->ga_len - 1]
24665
661d15592d3c patch 8.2.2871: unnessary VIM_ISDIGIT() calls, badly indented code
Bram Moolenaar <Bram@vim.org>
parents: 24645
diff changeset
8471 .isn_type == ISN_PROF_START)
661d15592d3c patch 8.2.2871: unnessary VIM_ISDIGIT() calls, badly indented code
Bram Moolenaar <Bram@vim.org>
parents: 24645
diff changeset
8472 // move the profile start after "endtry" so that it's not counted when
661d15592d3c patch 8.2.2871: unnessary VIM_ISDIGIT() calls, badly indented code
Bram Moolenaar <Bram@vim.org>
parents: 24645
diff changeset
8473 // the exception is rethrown.
661d15592d3c patch 8.2.2871: unnessary VIM_ISDIGIT() calls, badly indented code
Bram Moolenaar <Bram@vim.org>
parents: 24645
diff changeset
8474 --instr->ga_len;
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8475 #endif
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8476
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8477 // 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
8478 // done by ":finally".
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8479 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
8480 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
8481
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8482 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
8483 {
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8484 // 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
8485 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
8486 + 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
8487 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
8488 }
21371
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21353
diff changeset
8489 }
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21353
diff changeset
8490
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8491 compile_endblock(cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8492
23948
9854b4c6d5e6 patch 8.2.2516: test failure on s390
Bram Moolenaar <Bram@vim.org>
parents: 23927
diff changeset
8493 if (cctx->ctx_skip != SKIP_YES)
9854b4c6d5e6 patch 8.2.2516: test failure on s390
Bram Moolenaar <Bram@vim.org>
parents: 23927
diff changeset
8494 {
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8495 // 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
8496 // instruction
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8497 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
8498 if (cctx->ctx_skip != SKIP_YES
9854b4c6d5e6 patch 8.2.2516: test failure on s390
Bram Moolenaar <Bram@vim.org>
parents: 23927
diff changeset
8499 && generate_instr(cctx, ISN_ENDTRY) == NULL)
9854b4c6d5e6 patch 8.2.2516: test failure on s390
Bram Moolenaar <Bram@vim.org>
parents: 23927
diff changeset
8500 return NULL;
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8501 #ifdef FEAT_PROFILE
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
8502 if (cctx->ctx_compile_type == CT_PROFILE)
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8503 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
8504 #endif
23948
9854b4c6d5e6 patch 8.2.2516: test failure on s390
Bram Moolenaar <Bram@vim.org>
parents: 23927
diff changeset
8505 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8506 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8507 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8508
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8509 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8510 * compile "throw {expr}"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8511 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8512 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8513 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
8514 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8515 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
8516
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
8517 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
8518 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
8519 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
8520 return p;
24796
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
8521 if (may_generate_2STRING(-1, FALSE, cctx) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8522 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8523 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
8524 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8525
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8526 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8527 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8528
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8529 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8530 * 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
8531 * 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
8532 * 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
8533 * 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
8534 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8535 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
8536 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
8537 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8538 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
8539 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
8540 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
8541 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
8542 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
8543 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
8544 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
8545
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
8546 for (;;)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8547 {
23183
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
8548 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
8549 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
8550 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
8551 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
8552 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
8553
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
8554 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
8555 {
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
8556 // 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
8557 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
8558 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
8559 {
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
8560 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
8561 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
8562 }
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
8563 }
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
8564
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8565 ++count;
21835
b530ead4265a patch 8.2.1467: Vim9: :echomsg doesn't like a dict argument
Bram Moolenaar <Bram@vim.org>
parents: 21833
diff changeset
8566 prev = p;
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
8567 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
8568 }
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
8569
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
8570 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
8571 {
24471
baf75c8e1b7b patch 8.2.2775: Vim9: wrong line number used for some commands
Bram Moolenaar <Bram@vim.org>
parents: 24460
diff changeset
8572 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
8573
baf75c8e1b7b patch 8.2.2775: Vim9: wrong line number used for some commands
Bram Moolenaar <Bram@vim.org>
parents: 24460
diff changeset
8574 // 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
8575 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
8576
23183
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
8577 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
8578 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
8579 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
8580 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
8581 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
8582 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
8583 else
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
8584 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
8585
baf75c8e1b7b patch 8.2.2775: Vim9: wrong line number used for some commands
Bram Moolenaar <Bram@vim.org>
parents: 24460
diff changeset
8586 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
8587 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8588 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8589 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8590
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8591 /*
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 23199
diff changeset
8592 * 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
8593 * 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
8594 * 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
8595 */
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8596 static int
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8597 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
8598 {
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8599 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
8600 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
8601
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8602 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
8603 return FAIL;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8604 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
8605 }
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8606
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8607 /*
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8608 * :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
8609 * :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
8610 */
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8611 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
8612 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
8613 {
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8614 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
8615 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
8616 char *errormsg;
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
8617 int above = eap->forceit;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
8618
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8619 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
8620
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8621 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
8622 {
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8623 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
8624
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8625 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
8626 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
8627 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
8628 }
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8629 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
8630 ++line;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8631
23156
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8632 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
8633 {
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8634 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
8635 }
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8636 else
23156
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8637 {
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8638 // 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
8639 // "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
8640 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
8641 // 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
8642 return NULL;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8643 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
8644 lnum = -1;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8645 else
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8646 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
8647 if (above)
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8648 --lnum;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8649 }
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8650
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8651 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
8652 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
8653 }
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8654
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8655 /*
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8656 * 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
8657 */
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8658 static char_u *
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8659 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
8660 {
24834
adcd50a18236 patch 8.2.2955: Vim9: using filter in compiled command does not work
Bram Moolenaar <Bram@vim.org>
parents: 24826
diff changeset
8661 char_u *p;
adcd50a18236 patch 8.2.2955: Vim9: using filter in compiled command does not work
Bram Moolenaar <Bram@vim.org>
parents: 24826
diff changeset
8662 int has_expr = FALSE;
adcd50a18236 patch 8.2.2955: Vim9: using filter in compiled command does not work
Bram Moolenaar <Bram@vim.org>
parents: 24826
diff changeset
8663 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
8664
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
8665 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
8666 goto theend;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8667
24834
adcd50a18236 patch 8.2.2955: Vim9: using filter in compiled command does not work
Bram Moolenaar <Bram@vim.org>
parents: 24826
diff changeset
8668 // If there was a prececing command modifier, drop it and include it in the
adcd50a18236 patch 8.2.2955: Vim9: using filter in compiled command does not work
Bram Moolenaar <Bram@vim.org>
parents: 24826
diff changeset
8669 // EXEC command.
adcd50a18236 patch 8.2.2955: Vim9: using filter in compiled command does not work
Bram Moolenaar <Bram@vim.org>
parents: 24826
diff changeset
8670 if (cctx->ctx_has_cmdmod)
adcd50a18236 patch 8.2.2955: Vim9: using filter in compiled command does not work
Bram Moolenaar <Bram@vim.org>
parents: 24826
diff changeset
8671 {
adcd50a18236 patch 8.2.2955: Vim9: using filter in compiled command does not work
Bram Moolenaar <Bram@vim.org>
parents: 24826
diff changeset
8672 garray_T *instr = &cctx->ctx_instr;
adcd50a18236 patch 8.2.2955: Vim9: using filter in compiled command does not work
Bram Moolenaar <Bram@vim.org>
parents: 24826
diff changeset
8673 isn_T *isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1;
adcd50a18236 patch 8.2.2955: Vim9: using filter in compiled command does not work
Bram Moolenaar <Bram@vim.org>
parents: 24826
diff changeset
8674
adcd50a18236 patch 8.2.2955: Vim9: using filter in compiled command does not work
Bram Moolenaar <Bram@vim.org>
parents: 24826
diff changeset
8675 if (isn->isn_type == ISN_CMDMOD)
adcd50a18236 patch 8.2.2955: Vim9: using filter in compiled command does not work
Bram Moolenaar <Bram@vim.org>
parents: 24826
diff changeset
8676 {
adcd50a18236 patch 8.2.2955: Vim9: using filter in compiled command does not work
Bram Moolenaar <Bram@vim.org>
parents: 24826
diff changeset
8677 vim_regfree(isn->isn_arg.cmdmod.cf_cmdmod
adcd50a18236 patch 8.2.2955: Vim9: using filter in compiled command does not work
Bram Moolenaar <Bram@vim.org>
parents: 24826
diff changeset
8678 ->cmod_filter_regmatch.regprog);
adcd50a18236 patch 8.2.2955: Vim9: using filter in compiled command does not work
Bram Moolenaar <Bram@vim.org>
parents: 24826
diff changeset
8679 vim_free(isn->isn_arg.cmdmod.cf_cmdmod);
adcd50a18236 patch 8.2.2955: Vim9: using filter in compiled command does not work
Bram Moolenaar <Bram@vim.org>
parents: 24826
diff changeset
8680 --instr->ga_len;
adcd50a18236 patch 8.2.2955: Vim9: using filter in compiled command does not work
Bram Moolenaar <Bram@vim.org>
parents: 24826
diff changeset
8681 cctx->ctx_has_cmdmod = FALSE;
adcd50a18236 patch 8.2.2955: Vim9: using filter in compiled command does not work
Bram Moolenaar <Bram@vim.org>
parents: 24826
diff changeset
8682 }
adcd50a18236 patch 8.2.2955: Vim9: using filter in compiled command does not work
Bram Moolenaar <Bram@vim.org>
parents: 24826
diff changeset
8683 }
adcd50a18236 patch 8.2.2955: Vim9: using filter in compiled command does not work
Bram Moolenaar <Bram@vim.org>
parents: 24826
diff changeset
8684
20174
72b437855299 patch 8.2.0642: Vim9: using invalid index
Bram Moolenaar <Bram@vim.org>
parents: 20172
diff changeset
8685 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
8686 {
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
8687 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
8688 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
8689
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8690 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
8691
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8692 // 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
8693 // 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
8694 // 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
8695 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
8696 && *eap->arg == '!')
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8697 // :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
8698 usefilter = TRUE;
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8699 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
8700 {
21893
f19ac9b8b011 patch 8.2.1496: Vim9: cannot use " #" in a mapping
Bram Moolenaar <Bram@vim.org>
parents: 21883
diff changeset
8701 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
8702 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
8703 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
8704 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
8705 }
23477
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8706 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
8707 {
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8708 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
8709 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
8710 ++p;
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8711 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
8712 ++p;
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8713 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
8714 if (*p == '|')
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8715 {
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8716 *p = NUL;
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8717 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
8718 }
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8719 }
21156
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8720 }
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8721
20172
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
8722 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
8723 {
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
8724 // 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
8725 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
8726 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
8727 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
8728 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
8729 }
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
8730
23344
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8731 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
8732 && STRLEN(eap->arg) > 4)
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8733 {
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8734 int delim = *eap->arg;
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8735
23505
bb29b09902d5 patch 8.2.2295: incsearch does not detect empty pattern properly
Bram Moolenaar <Bram@vim.org>
parents: 23497
diff changeset
8736 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
8737 if (*p == delim)
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8738 {
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8739 eap->arg = p + 1;
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8740 has_expr = TRUE;
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8741 }
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8742 }
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8743
23521
0ef920a03380 patch 8.2.2303: Vim9: backtick expansion doesn't work for :foldopen
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
8744 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
8745 {
0ef920a03380 patch 8.2.2303: Vim9: backtick expansion doesn't work for :foldopen
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
8746 // 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
8747 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
8748 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
8749 }
0ef920a03380 patch 8.2.2303: Vim9: backtick expansion doesn't work for :foldopen
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
8750
20172
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
8751 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
8752 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8753 int count = 0;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8754 char_u *start = skipwhite(line);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8755
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8756 // :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
8757 // PUSHS ":cmd xxx"
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8758 // eval expr1
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8759 // PUSHS "yyy"
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8760 // eval expr2
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8761 // PUSHS "zzz"
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8762 // EXECCONCAT 5
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8763 for (;;)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8764 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8765 if (p > start)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8766 {
20830
9064044fd4f6 patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
8767 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
8768 ++count;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8769 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8770 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
8771 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
8772 return NULL;
24796
7c1375eb1636 patch 8.2.2936: Vim9: converting number to bool uses wrong stack offset
Bram Moolenaar <Bram@vim.org>
parents: 24776
diff changeset
8773 may_generate_2STRING(-1, TRUE, cctx);
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8774 ++count;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8775 p = skipwhite(p);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8776 if (*p != '`')
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8777 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
8778 emsg(_(e_missing_backtick));
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8779 return NULL;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8780 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8781 start = p + 1;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8782
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8783 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
8784 if (p == NULL)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8785 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8786 if (*skipwhite(start) != NUL)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8787 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8788 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
8789 ++count;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8790 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8791 break;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8792 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8793 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8794 generate_EXECCONCAT(cctx, count);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8795 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8796 else
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8797 generate_EXEC(cctx, line);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8798
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8799 theend:
21156
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8800 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
8801 {
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8802 // 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
8803 --nextcmd;
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8804 *nextcmd = '|';
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8805 }
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8806
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8807 return nextcmd;
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8808 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8809
24826
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8810 /*
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8811 * A script command with heredoc, e.g.
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8812 * ruby << EOF
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8813 * command
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8814 * EOF
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8815 * Has been turned into one long line with NL characters by
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8816 * get_function_body():
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8817 * ruby << EOF<NL> command<NL>EOF
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8818 */
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8819 static char_u *
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8820 compile_script(char_u *line, cctx_T *cctx)
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8821 {
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8822 if (cctx->ctx_skip != SKIP_YES)
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8823 {
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8824 isn_T *isn;
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8825
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8826 if ((isn = generate_instr(cctx, ISN_EXEC_SPLIT)) == NULL)
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8827 return NULL;
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8828 isn->isn_arg.string = vim_strsave(line);
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8829 }
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8830 return (char_u *)"";
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8831 }
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
8832
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8833
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8834 /*
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8835 * :s/pat/repl/
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8836 */
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8837 static char_u *
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8838 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
8839 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8840 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
8841 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
8842
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8843 if (expr != NULL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8844 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8845 int delimiter = *cmd++;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8846
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8847 // 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
8848 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
8849 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
8850 {
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8851 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
8852 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
8853 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
8854 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
8855 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
8856 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
8857 isn_T *isn;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8858
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8859 cmd += 3;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8860 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
8861
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
8862 // 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
8863 // 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
8864 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
8865 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
8866 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
8867 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
8868 if (end[-1] == NUL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8869 end[-1] = delimiter;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8870 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
8871 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
8872
24510
b5786b4de9d1 patch 8.2.2795: Coverity warns for not using return value
Bram Moolenaar <Bram@vim.org>
parents: 24502
diff changeset
8873 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
8874 || 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
8875 {
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8876 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
8877 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
8878 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
8879 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
8880 return NULL;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8881 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8882
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8883 // 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
8884 // 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
8885 // 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
8886 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
8887 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
8888 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
8889
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8890 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
8891 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
8892 {
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8893 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
8894
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8895 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
8896 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
8897 vim_free(instr);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8898 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
8899 }
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8900 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
8901 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
8902
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8903 // skip over flags
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8904 if (*end == '&')
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8905 ++end;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8906 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
8907 ++end;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8908 return end;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8909 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8910 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8911
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8912 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
8913 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8914
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8915 static char_u *
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8916 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
8917 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8918 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
8919 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
8920
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8921 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
8922 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8923 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
8924 {
24512
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8925 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
8926 {
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
8927 // 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
8928 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
8929 cctx) == FAIL)
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8930 return NULL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8931 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8932
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8933 // 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
8934 // in the variable.
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8935 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
8936
24512
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8937 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
8938 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
8939
24512
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8940 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
8941 {
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8942 // 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
8943 // 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
8944 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
8945 &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
8946 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
8947 }
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8948 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
8949 return NULL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8950
24512
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8951 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
8952 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
8953 return arg + 3;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8954 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8955 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
8956 return NULL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8957 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8958
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8959 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
8960 {
24512
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8961 int append = FALSE;
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8962
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8963 // 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
8964 arg += 2;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8965 if (*arg == '>')
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8966 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8967 ++arg;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8968 append = TRUE;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8969 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8970 arg = skipwhite(arg);
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8971
24512
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8972 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
8973 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
8974 return NULL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8975 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
8976 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
8977 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
8978 {
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8979 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
8980 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
8981 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
8982 }
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8983
53871095bb65 patch 8.2.2796: Vim9: redir to variable does not accept an index
Bram Moolenaar <Bram@vim.org>
parents: 24510
diff changeset
8984 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
8985 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8986
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8987 // 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
8988 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
8989 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8990
24594
5c456a88f651 patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents: 24592
diff changeset
8991 #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
8992 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
8993 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
8994 {
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8995 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
8996 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
8997
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
8998 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
8999 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
9000 return NULL;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9001 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
9002
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9003 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
9004 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
9005 return NULL;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9006
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9007 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
9008 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
9009 return NULL;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9010 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
9011 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
9012 return NULL;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9013 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
9014 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
9015 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
9016
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9017 return p;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9018 }
24594
5c456a88f651 patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents: 24592
diff changeset
9019 #endif
24590
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9020
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9021 /*
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
9022 * 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
9023 * 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
9024 */
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20419
diff changeset
9025 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
9026 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
9027 {
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
9028 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
9029
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
9030 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
9031 {
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
9032 // 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
9033 // 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
9034 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
9035 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
9036 ++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
9037 }
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
9038
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
9039 // 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
9040 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
9041 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
9042 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
9043 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
9044 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
9045 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
9046 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
9047 dfunc->df_name = vim_strsave(ufunc->uf_name);
24918
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
9048 ga_init2(&dfunc->df_var_names, sizeof(char_u *), 10);
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
9049 ++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
9050 ++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
9051 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
9052 }
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
9053
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
9054 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9055 * 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
9056 * 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
9057 * 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
9058 * 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
9059 * 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
9060 * 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
9061 * 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
9062 * "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
9063 * 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
9064 * "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
9065 * 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
9066 */
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20419
diff changeset
9067 int
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9068 compile_def_function(
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
9069 ufunc_T *ufunc,
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
9070 int check_return_type,
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
9071 compiletype_T compile_type,
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
9072 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
9073 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9074 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
9075 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
9076 char_u *p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9077 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
9078 cctx_T cctx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9079 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
9080 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
9081 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
9082 int ret = FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9083 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
9084 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
9085 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
9086 int do_estack_push;
21463
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
9087 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
9088 #ifdef FEAT_PROFILE
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9089 int prof_lnum = -1;
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
9090 #endif
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
9091 int debug_lnum = -1;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9092
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
9093 // 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
9094 // 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
9095 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
9096 {
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
9097 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
9098 + ufunc->uf_dfunc_idx;
24926
e20d34db7cf4 patch 8.2.3000: Vim9: warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents: 24918
diff changeset
9099 isn_T *instr_dest = NULL;
24918
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
9100
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
9101 switch (compile_type)
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
9102 {
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
9103 case CT_PROFILE:
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
9104 #ifdef FEAT_PROFILE
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
9105 instr_dest = dfunc->df_instr_prof; break;
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
9106 #endif
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
9107 case CT_NONE: instr_dest = dfunc->df_instr; break;
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
9108 case CT_DEBUG: instr_dest = dfunc->df_instr_debug; break;
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
9109 }
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
9110 if (instr_dest != NULL)
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
9111 // Was compiled in this mode before: Free old instructions.
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
9112 delete_def_function_contents(dfunc, FALSE);
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
9113 ga_clear_strings(&dfunc->df_var_names);
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
9114 }
21463
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
9115 else
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
9116 {
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
9117 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
9118 return FAIL;
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
9119 new_def_function = TRUE;
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
9120 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9121
21281
13b1567ae0c6 patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
9122 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
9123
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 20005
diff changeset
9124 CLEAR_FIELD(cctx);
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9125
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
9126 cctx.ctx_compile_type = compile_type;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9127 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
9128 cctx.ctx_lnum = -1;
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
9129 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
9130 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
9131 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
9132 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
9133 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
9134 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
9135 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
9136
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
9137 // 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
9138 // 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
9139 // 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
9140 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
9141 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
9142
24539
3a290891a015 patch 8.2.2809: Vim9: :def function compilation fails when using :legacy
Bram Moolenaar <Bram@vim.org>
parents: 24533
diff changeset
9143 // 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
9144 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
9145
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
9146 // 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
9147 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
9148 if (do_estack_push)
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
9149 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
9150 estack_compiling = TRUE;
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
9151
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
9152 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
9153 {
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
9154 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
9155 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
9156 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
9157 int i;
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
9158 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
9159 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
9160 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
9161
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
9162 // 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
9163 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
9164 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
9165 {
19946
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
9166 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
9167 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
9168 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
9169 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
9170 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
9171 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
9172 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
9173
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
9174 // 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
9175 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
9176 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
9177
26d3c1539bcc patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents: 24087
diff changeset
9178 // 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
9179 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
9180
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
9181 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
9182 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
9183
26d3c1539bcc patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents: 24087
diff changeset
9184 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
9185 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
9186 goto erret;
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
9187
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
9188 // 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
9189 // 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
9190 // specified type.
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
9191 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
9192 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
9193 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
9194 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
9195 {
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
9196 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
9197 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
9198 }
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
9199 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
9200 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
9201 goto erret;
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
9202
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
9203 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
9204 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
9205
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
9206 // 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
9207 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
9208 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
9209 }
21469
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
9210
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
9211 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
9212 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
9213 }
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
9214
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
9215 /*
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
9216 * 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
9217 */
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9218 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9219 {
21689
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21683
diff changeset
9220 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
9221 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
9222 char_u *cmd;
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
9223 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
9224
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
9225 // 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
9226 // 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
9227 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
9228 goto erret;
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
9229
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9230 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
9231 // 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
9232 ++line;
20949
62912ad41aff patch 8.2.1026: Vim9: cannot break the line after "->"
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
9233 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
9234 && !(*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
9235 || 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
9236 {
21455
8cc1555f2445 patch 8.2.1278: Vim9: line break after "->" only allowed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21443
diff changeset
9237 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
9238 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9239 }
24158
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
9240 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
9241 goto erret;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9242 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9243 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
9244 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
9245 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
9246 {
20055
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9247 // beyond the last line
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
9248 #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
9249 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
9250 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
9251 #endif
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9252 break;
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9253 }
24444
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
9254 // 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
9255 // may change it.
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
9256 if (line != NULL)
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
9257 {
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
9258 line = vim_strsave(line);
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
9259 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
9260 line_to_free = line;
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
9261 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9262 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9263
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 20005
diff changeset
9264 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
9265 ea.cmdlinep = &line;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9266 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
9267
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9268 if (*ea.cmd == '#')
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9269 {
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9270 // "#" starts a comment
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9271 line = (char_u *)"";
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9272 continue;
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9273 }
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9274
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
9275 #ifdef FEAT_PROFILE
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
9276 if (cctx.ctx_compile_type == CT_PROFILE && cctx.ctx_lnum != prof_lnum
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
9277 && 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
9278 {
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9279 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
9280
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9281 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
9282 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
9283 }
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
9284 #endif
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
9285 if (cctx.ctx_compile_type == CT_DEBUG && cctx.ctx_lnum != debug_lnum
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
9286 && cctx.ctx_skip != SKIP_YES)
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
9287 {
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
9288 debug_lnum = cctx.ctx_lnum;
24918
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
9289 generate_instr_debug(&cctx);
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
9290 }
25004
70f55a30f03c patch 8.2.3039: Vim9: breakpoint at a comment line does not work
Bram Moolenaar <Bram@vim.org>
parents: 24984
diff changeset
9291 cctx.ctx_prev_lnum = cctx.ctx_lnum + 1;
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9292
20055
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9293 // 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
9294 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
9295 {
20055
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9296 case '}':
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9297 {
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9298 // "}" 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
9299 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
9300 ? 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
9301
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9302 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
9303 {
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9304 compile_endblock(&cctx);
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9305 line = ea.cmd;
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9306 }
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9307 else
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9308 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
9309 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
9310 goto erret;
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9311 }
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9312 if (line != NULL)
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9313 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
9314 continue;
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9315 }
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9316
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9317 case '{':
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9318 // "{" 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
9319 // "{'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
9320 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
9321 {
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9322 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
9323 continue;
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9324 }
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
9325 break;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9326 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9327
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9328 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9329 * COMMAND MODIFIERS
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9330 */
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
9331 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
9332 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
9333 == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9334 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9335 if (errormsg != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9336 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9337 // 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
9338 line = (char_u *)"";
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9339 continue;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9340 }
22699
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 22697
diff changeset
9341 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
9342 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
9343
22772
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
9344 // 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
9345 // 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
9346 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
9347 {
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
9348 if (*p == ':')
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
9349 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
9350 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
9351 break;
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
9352 }
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
9353
25030
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9354 // Skip ":call" to get to the function name, unless using :legacy
21751
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21743
diff changeset
9355 p = ea.cmd;
25030
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9356 if (!(local_cmdmod.cmod_flags & CMOD_LEGACY))
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9357 {
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9358 if (checkforcmd(&ea.cmd, "call", 3))
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9359 {
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9360 if (*ea.cmd == '(')
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9361 // not for "call()"
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9362 ea.cmd = p;
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9363 else
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9364 ea.cmd = skipwhite(ea.cmd);
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9365 }
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9366
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9367 if (!starts_with_colon)
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9368 {
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9369 int assign;
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9370
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9371 // Check for assignment after command modifiers.
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9372 assign = may_compile_assignment(&ea, &line, &cctx);
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9373 if (assign == OK)
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9374 goto nextline;
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9375 if (assign == FAIL)
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9376 goto erret;
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9377 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9378 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9379
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9380 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9381 * COMMAND after range
21335
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
9382 * '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
9383 * "++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
9384 */
20982
bb49b5090a9c patch 8.2.1042: Vim9: cannot put an operator on the next line
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
9385 cmd = ea.cmd;
25030
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9386 if (!(local_cmdmod.cmod_flags & CMOD_LEGACY)
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9387 && (starts_with_colon || !(*cmd == '\''
214fddf4c765 patch 8.2.3052: Vim9: "legacy call" does not work
Bram Moolenaar <Bram@vim.org>
parents: 25028
diff changeset
9388 || (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
9389 {
22260
d7c1e3efa88e patch 8.2.1679: Vim9: ":*" is not recognized as a range
Bram Moolenaar <Bram@vim.org>
parents: 22236
diff changeset
9390 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
9391 if (ea.cmd > cmd)
21335
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
9392 {
21901
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
9393 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
9394 {
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
9395 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
9396 goto erret;
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
9397 }
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
9398 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
9399 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
9400 {
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
9401 // 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
9402 // 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
9403 // 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
9404 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
9405 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
9406 goto nextline;
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
9407 }
21335
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
9408 }
20982
bb49b5090a9c patch 8.2.1042: Vim9: cannot put an operator on the next line
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
9409 }
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
9410 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
9411 ? 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
9412
23513
872239543313 patch 8.2.2299: Vim9: invalid memory access making error message flaky
Bram Moolenaar <Bram@vim.org>
parents: 23505
diff changeset
9413 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
9414 {
872239543313 patch 8.2.2299: Vim9: invalid memory access making error message flaky
Bram Moolenaar <Bram@vim.org>
parents: 23505
diff changeset
9415 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
9416 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
9417 goto erret;
872239543313 patch 8.2.2299: Vim9: invalid memory access making error message flaky
Bram Moolenaar <Bram@vim.org>
parents: 23505
diff changeset
9418 }
872239543313 patch 8.2.2299: Vim9: invalid memory access making error message flaky
Bram Moolenaar <Bram@vim.org>
parents: 23505
diff changeset
9419
24531
3bfec39ce31c patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 24516
diff changeset
9420 // 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
9421 if (local_cmdmod.cmod_flags & CMOD_LEGACY)
24645
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
9422 {
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
9423 char_u *start = ea.cmd;
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
9424
24776
7464d4c927f5 patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
9425 switch (ea.cmdidx)
7464d4c927f5 patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
9426 {
7464d4c927f5 patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
9427 case CMD_if:
7464d4c927f5 patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
9428 case CMD_elseif:
7464d4c927f5 patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
9429 case CMD_else:
7464d4c927f5 patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
9430 case CMD_endif:
7464d4c927f5 patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
9431 case CMD_for:
7464d4c927f5 patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
9432 case CMD_endfor:
7464d4c927f5 patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
9433 case CMD_continue:
7464d4c927f5 patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
9434 case CMD_break:
7464d4c927f5 patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
9435 case CMD_while:
7464d4c927f5 patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
9436 case CMD_endwhile:
7464d4c927f5 patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
9437 case CMD_try:
7464d4c927f5 patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
9438 case CMD_catch:
7464d4c927f5 patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
9439 case CMD_finally:
7464d4c927f5 patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
9440 case CMD_endtry:
7464d4c927f5 patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
9441 semsg(_(e_cannot_use_legacy_with_command_str), ea.cmd);
7464d4c927f5 patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
9442 goto erret;
7464d4c927f5 patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
9443 default: break;
7464d4c927f5 patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
9444 }
7464d4c927f5 patch 8.2.2926: Vim9: no good error for using :legacy in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24717
diff changeset
9445
24645
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
9446 // ":legacy return expr" needs to be handled differently.
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
9447 if (checkforcmd(&start, "return", 4))
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
9448 ea.cmdidx = CMD_return;
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
9449 else
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
9450 ea.cmdidx = CMD_legacy;
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
9451 }
24531
3bfec39ce31c patch 8.2.2805: Vim9: cannot use legacy syntax in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 24516
diff changeset
9452
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9453 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
9454 {
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
9455 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
9456 {
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
9457 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
9458 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
9459 }
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
9460
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9461 // 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
9462 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
9463 {
23254
4b7e996354e0 patch 8.2.2173: Vim9: get internal error when assigning to undefined variable
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
9464 // 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
9465 // 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
9466 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
9467 goto erret;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9468 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9469 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9470
21957
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9471 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
9472 && 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
9473 && ea.cmdidx != CMD_else
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9474 && ea.cmdidx != CMD_endif
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9475 && ea.cmdidx != CMD_endfor
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9476 && ea.cmdidx != CMD_endwhile
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9477 && ea.cmdidx != CMD_catch
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9478 && ea.cmdidx != CMD_finally
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9479 && ea.cmdidx != CMD_endtry)
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9480 {
21957
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9481 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
9482 goto erret;
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9483 }
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9484
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9485 p = skipwhite(p);
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9486 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
9487 && 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
9488 {
22276
753452747ae5 patch 8.2.1687: Vim9: out of bounds error
Bram Moolenaar <Bram@vim.org>
parents: 22274
diff changeset
9489 if (ea.cmdidx >= 0)
753452747ae5 patch 8.2.1687: Vim9: out of bounds error
Bram Moolenaar <Bram@vim.org>
parents: 22274
diff changeset
9490 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
9491 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
9492 {
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9493 ea.forceit = TRUE;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9494 p = skipwhite(p + 1);
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9495 }
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9496 }
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9497
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9498 switch (ea.cmdidx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9499 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9500 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
9501 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
9502 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
9503 break;
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
9504
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9505 case CMD_function:
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
9506 // 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
9507 // function?
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
9508 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
9509 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9510
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9511 case CMD_return:
24645
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
9512 line = compile_return(p, check_return_type,
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
9513 local_cmdmod.cmod_flags & CMOD_LEGACY, &cctx);
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9514 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
9515 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9516
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9517 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
9518 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
9519 break;
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
9520 case CMD_var:
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
9521 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
9522 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
9523 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
9524 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
9525 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
9526 if (line == p)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
9527 line = NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9528 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9529
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9530 case CMD_unlet:
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9531 case CMD_unlockvar:
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9532 case CMD_lockvar:
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9533 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
9534 break;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9535
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9536 case CMD_import:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9537 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
9538 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9539
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9540 case CMD_if:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9541 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
9542 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9543 case CMD_elseif:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9544 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
9545 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
9546 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9547 case CMD_else:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9548 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
9549 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
9550 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9551 case CMD_endif:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9552 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
9553 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9554
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9555 case CMD_while:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9556 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
9557 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9558 case CMD_endwhile:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9559 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
9560 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
9561 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9562
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9563 case CMD_for:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9564 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
9565 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9566 case CMD_endfor:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9567 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
9568 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
9569 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9570 case CMD_continue:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9571 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
9572 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9573 case CMD_break:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9574 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
9575 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9576
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9577 case CMD_try:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9578 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
9579 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9580 case CMD_catch:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9581 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
9582 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
9583 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9584 case CMD_finally:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9585 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
9586 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
9587 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9588 case CMD_endtry:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9589 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
9590 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
9591 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9592 case CMD_throw:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9593 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
9594 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9595
21196
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
9596 case CMD_eval:
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
9597 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
9598 goto erret;
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
9599
21957
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9600 // drop the result
21196
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
9601 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
9602
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
9603 line = skipwhite(p);
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
9604 break;
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
9605
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9606 case CMD_echo:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9607 case CMD_echon:
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
9608 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
9609 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
9610 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
9611 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
9612 break;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9613
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
9614 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
9615 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
9616 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
9617 break;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
9618
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9619 case CMD_substitute:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9620 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
9621 line = (char_u *)"";
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9622 else
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9623 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9624 ea.arg = p;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9625 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
9626 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9627 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9628
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9629 case CMD_redir:
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9630 ea.arg = p;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9631 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
9632 break;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9633
24590
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9634 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
9635 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
9636 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
9637 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
9638 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
9639 case CMD_lgetexpr:
24594
5c456a88f651 patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents: 24592
diff changeset
9640 #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
9641 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
9642 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
9643 #else
5c456a88f651 patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents: 24592
diff changeset
9644 ex_ni(&ea);
5c456a88f651 patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents: 24592
diff changeset
9645 line = NULL;
5c456a88f651 patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents: 24592
diff changeset
9646 #endif
24590
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9647 break;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
9648
21957
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9649 // 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
9650
21516
c7b2ce90c2de patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
9651 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
9652 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
9653 case CMD_insert:
23978
54b2aa1f0d42 patch 8.2.2531: Vim9: the :k command is obscure
Bram Moolenaar <Bram@vim.org>
parents: 23966
diff changeset
9654 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
9655 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
9656 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
9657 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
9658 goto erret;
c7b2ce90c2de patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
9659
21210
44611891e22c patch 8.2.1156: Vim9: No error for invalid command in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
9660 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
9661 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
9662 {
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9663 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
9664 goto erret;
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9665 }
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9666 // 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
9667 line = (char_u *)"";
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9668 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
9669
24826
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
9670 case CMD_lua:
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
9671 case CMD_mzscheme:
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
9672 case CMD_perl:
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
9673 case CMD_py3:
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
9674 case CMD_python3:
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
9675 case CMD_python:
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
9676 case CMD_pythonx:
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
9677 case CMD_ruby:
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
9678 case CMD_tcl:
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
9679 ea.arg = p;
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
9680 if (vim_strchr(line, '\n') == NULL)
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
9681 line = compile_exec(line, &ea, &cctx);
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
9682 else
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
9683 // heredoc lines have been concatenated with NL
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
9684 // characters in get_function_body()
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
9685 line = compile_script(line, &cctx);
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
9686 break;
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
9687
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9688 default:
24826
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
9689 // Not recognized, execute with do_cmdline_cmd().
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
9690 ea.arg = p;
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
9691 line = compile_exec(line, &ea, &cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9692 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9693 }
21901
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
9694 nextline:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9695 if (line == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9696 goto erret;
19894
ea4f8e789627 patch 8.2.0503: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
9697 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
9698
22691
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
9699 // 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
9700 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
9701
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9702 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
9703 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9704 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
9705 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9706 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9707 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9708
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9709 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
9710 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9711 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
9712 emsg(_(e_endif));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9713 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
9714 emsg(_(e_endwhile));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9715 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
9716 emsg(_(e_endfor));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9717 else
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
9718 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
9719 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9720 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9721
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9722 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
9723 {
24893
1d6242cf1163 patch 8.2.2984: Vim9: test fails because of missing return statement
Bram Moolenaar <Bram@vim.org>
parents: 24890
diff changeset
9724 if (ufunc->uf_ret_type->tt_type == VAR_UNKNOWN)
1d6242cf1163 patch 8.2.2984: Vim9: test fails because of missing return statement
Bram Moolenaar <Bram@vim.org>
parents: 24890
diff changeset
9725 ufunc->uf_ret_type = &t_void;
1d6242cf1163 patch 8.2.2984: Vim9: test fails because of missing return statement
Bram Moolenaar <Bram@vim.org>
parents: 24890
diff changeset
9726 else if (ufunc->uf_ret_type->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
9727 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
9728 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
9729 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9730 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9731
24936
345619f35112 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents: 24928
diff changeset
9732 // Return void if there is no return at the end.
345619f35112 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents: 24928
diff changeset
9733 generate_instr(&cctx, ISN_RETURN_VOID);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9734 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9735
24406
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
9736 // 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
9737 // function compiled.
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
9738 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
9739 {
8288884fdfe1 patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents: 19862
diff changeset
9740 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
9741 + 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
9742 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
9743 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
9744 #ifdef FEAT_PROFILE
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
9745 if (cctx.ctx_compile_type == CT_PROFILE)
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9746 {
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9747 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
9748 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
9749 }
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9750 else
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
9751 #endif
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
9752 if (cctx.ctx_compile_type == CT_DEBUG)
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
9753 {
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
9754 dfunc->df_instr_debug = instr->ga_data;
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
9755 dfunc->df_instr_debug_count = instr->ga_len;
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
9756 }
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
9757 else
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9758 {
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9759 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
9760 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
9761 }
24918
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
9762 dfunc->df_varcount = dfunc->df_var_names.ga_len;
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22369
diff changeset
9763 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
9764 if (cctx.ctx_outer_used)
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
9765 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
9766 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
9767 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9768
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9769 ret = OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9770
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9771 erret:
24406
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
9772 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
9773 {
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
9774 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
9775 + 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
9776
24928
cf4bc18a3931 patch 8.2.3001: Vim9: memory leak when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 24926
diff changeset
9777 // Compiling aborted, free the generated instructions.
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
9778 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
9779 VIM_CLEAR(dfunc->df_name);
24928
cf4bc18a3931 patch 8.2.3001: Vim9: memory leak when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 24926
diff changeset
9780 ga_clear_strings(&dfunc->df_var_names);
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9781
21463
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
9782 // 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
9783 // might as well remove it.
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
9784 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
9785 && 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
9786 {
20534
ae758aa4ee5e patch 8.2.0821: Vim9: memory leak in expr test
Bram Moolenaar <Bram@vim.org>
parents: 20532
diff changeset
9787 --def_functions.ga_len;
21463
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
9788 ufunc->uf_dfunc_idx = 0;
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
9789 }
24404
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
9790 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
9791
19896
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
9792 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
9793 drop_scope(&cctx);
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
9794
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9795 if (errormsg != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9796 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
9797 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
9798 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
9799 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9800
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9801 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
9802 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9803 if (ret == OK)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9804 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9805 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
9806 ret = FAIL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9807 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9808 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
9809 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
9810 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9811
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9812 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
9813 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
9814 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
9815 if (do_estack_push)
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
9816 estack_pop();
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
9817
24444
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
9818 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
9819 free_imported(&cctx);
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
9820 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
9821 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
9822 return ret;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9823 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9824
20532
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9825 void
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9826 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
9827 {
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9828 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
9829 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
9830
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9831 // 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
9832 // argument types.
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9833 // 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
9834 // 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
9835 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
9836 {
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
9837 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
9838 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
9839 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
9840 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
9841 // 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
9842 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
9843 argcount + varargs,
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9844 &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
9845 return;
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9846 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
9847 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
9848 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
9849 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
9850 {
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9851 int i;
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9852
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9853 // 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
9854 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
9855 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
9856 }
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9857 else
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9858 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
9859 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
9860 if (varargs)
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9861 {
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9862 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
9863 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
9864 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
9865 }
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9866 }
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9867 else
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9868 // 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
9869 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
9870 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
9871 }
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9872
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9873
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9874 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9875 * 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
9876 */
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9877 void
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9878 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
9879 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9880 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
9881 {
22973
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
9882 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
9883 case ISN_EXEC:
24826
a8d64f1a223b patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents: 24796
diff changeset
9884 case ISN_EXEC_SPLIT:
24645
668df21d8bc6 patch 8.2.2861: Vim9: "legacy return" is not recognized as a return statement
Bram Moolenaar <Bram@vim.org>
parents: 24637
diff changeset
9885 case ISN_LEGACY_EVAL:
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
9886 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
9887 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
9888 case ISN_LOADENV:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9889 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
9890 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
9891 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
9892 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
9893 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
9894 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
9895 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
9896 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
9897 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
9898 case ISN_STOREB:
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
9899 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
9900 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
9901 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
9902 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
9903 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
9904 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
9905 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9906
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9907 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
9908 {
cca0a1b4e878 patch 8.2.2786: Vim9: memory leak when using :s with expression
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
9909 int idx;
cca0a1b4e878 patch 8.2.2786: Vim9: memory leak when using :s with expression
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
9910 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
9911
cca0a1b4e878 patch 8.2.2786: Vim9: memory leak when using :s with expression
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
9912 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
9913 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
9914 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
9915 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
9916 }
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9917 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9918
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
9919 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
9920 {
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
9921 int idx;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
9922 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
9923
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
9924 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
9925 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
9926 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
9927 }
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
9928 break;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24602
diff changeset
9929
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9930 case ISN_LOADS:
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
9931 case ISN_STORES:
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
9932 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
9933 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9934
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9935 case ISN_UNLET:
20099
058b41f85bcb patch 8.2.0605: Vim9: cannot unlet an environment variable
Bram Moolenaar <Bram@vim.org>
parents: 20091
diff changeset
9936 case ISN_UNLETENV:
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9937 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
9938 break;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9939
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9940 case ISN_STOREOPT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9941 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
9942 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9943
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9944 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
9945 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
9946 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9947
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
9948 case ISN_PUSHJOB:
19562
6b7719b8f9b9 patch 8.2.0338: build failure without the channel feature
Bram Moolenaar <Bram@vim.org>
parents: 19558
diff changeset
9949 #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
9950 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
9951 #endif
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
9952 break;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
9953
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
9954 case ISN_PUSHCHANNEL:
19562
6b7719b8f9b9 patch 8.2.0338: build failure without the channel feature
Bram Moolenaar <Bram@vim.org>
parents: 19558
diff changeset
9955 #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
9956 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
9957 #endif
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
9958 break;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
9959
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9960 case ISN_UCALL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9961 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
9962 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9963
20283
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
9964 case ISN_FUNCREF:
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
9965 {
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
9966 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
9967 + 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
9968 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
9969
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
9970 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
9971 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
9972 }
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
9973 break;
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
9974
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
9975 case ISN_DCALL:
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
9976 {
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
9977 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
9978 + 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
9979
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22369
diff changeset
9980 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
9981 && 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
9982 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
9983 }
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
9984 break;
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
9985
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
9986 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
9987 {
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
9988 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
9989 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
9990
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
9991 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
9992 {
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
9993 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
9994 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
9995 }
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
9996
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
9997 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
9998 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
9999 }
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
10000 break;
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
10001
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
10002 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
10003 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
10004 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
10005 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
10006
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
10007 case ISN_CMDMOD:
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
10008 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
10009 ->cmod_filter_regmatch.regprog);
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
10010 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
10011 break;
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
10012
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
10013 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
10014 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
10015 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
10016 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
10017
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
10018 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
10019 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
10020 break;
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
10021
24590
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
10022 case ISN_CEXPR_CORE:
24592
ae2eb2c496ed patch 8.2.2835: Vim9: leaking memory in :cexpr
Bram Moolenaar <Bram@vim.org>
parents: 24590
diff changeset
10023 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
10024 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
10025 break;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24539
diff changeset
10026
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10027 case ISN_2BOOL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10028 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
10029 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
10030 case ISN_ADDBLOB:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10031 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
10032 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
10033 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
10034 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
10035 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
10036 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
10037 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
10038 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
10039 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
10040 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
10041 case ISN_CHECKNR:
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
10042 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
10043 case ISN_COMPAREANY:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10044 case ISN_COMPAREBLOB:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10045 case ISN_COMPAREBOOL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10046 case ISN_COMPAREDICT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10047 case ISN_COMPAREFLOAT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10048 case ISN_COMPAREFUNC:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10049 case ISN_COMPARELIST:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10050 case ISN_COMPARENR:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10051 case ISN_COMPARESPECIAL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10052 case ISN_COMPARESTRING:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10053 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
10054 case ISN_COND2BOOL:
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
10055 case ISN_DEBUG:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10056 case ISN_DROP:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10057 case ISN_ECHO:
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
10058 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
10059 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
10060 case ISN_ENDTRY:
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
10061 case ISN_EXECCONCAT:
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
10062 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
10063 case ISN_FINALLY:
24895
e61a2085c89b patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents: 24893
diff changeset
10064 case ISN_FINISH:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10065 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
10066 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
10067 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
10068 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
10069 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
10070 case ISN_LISTINDEX:
21828
af5db9b6d210 patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21826
diff changeset
10071 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
10072 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
10073 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
10074 case ISN_LOADGDICT:
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
10075 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
10076 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
10077 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
10078 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
10079 case ISN_LOADWDICT:
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
10080 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
10081 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
10082 case ISN_NEGATENR:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10083 case ISN_NEWDICT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10084 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
10085 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
10086 case ISN_OPFLOAT:
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
10087 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
10088 case ISN_PCALL:
19862
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19860
diff changeset
10089 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
10090 case ISN_PROF_END:
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
10091 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
10092 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
10093 case ISN_PUSHF:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10094 case ISN_PUSHNR:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10095 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
10096 case ISN_PUT:
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
10097 case ISN_REDIREND:
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
10098 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
10099 case ISN_RETURN:
24936
345619f35112 patch 8.2.3005: Vim9: using a void value does not give a proper error message
Bram Moolenaar <Bram@vim.org>
parents: 24928
diff changeset
10100 case ISN_RETURN_VOID:
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
10101 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
10102 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
10103 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
10104 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
10105 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
10106 case ISN_STOREOUTER:
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
10107 case ISN_STORERANGE:
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
10108 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
10109 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
10110 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
10111 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
10112 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
10113 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
10114 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
10115 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
10116 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
10117 // nothing allocated
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10118 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10119 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10120 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10121
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10122 /*
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
10123 * 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
10124 */
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
10125 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
10126 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
10127 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
10128 int idx;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
10129
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
10130 ga_clear(&dfunc->df_def_args_isn);
24918
f11779c1d123 patch 8.2.2996: Vim9: when debugging cannot inspect local variables
Bram Moolenaar <Bram@vim.org>
parents: 24914
diff changeset
10131 ga_clear_strings(&dfunc->df_var_names);
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
10132
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
10133 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
10134 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
10135 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
10136 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
10137 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
10138 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
10139 }
24903
99324f6b535a patch 8.2.2989: Vim9: memory leak when debugging a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24897
diff changeset
10140 if (dfunc->df_instr_debug != NULL)
99324f6b535a patch 8.2.2989: Vim9: memory leak when debugging a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24897
diff changeset
10141 {
99324f6b535a patch 8.2.2989: Vim9: memory leak when debugging a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24897
diff changeset
10142 for (idx = 0; idx < dfunc->df_instr_debug_count; ++idx)
99324f6b535a patch 8.2.2989: Vim9: memory leak when debugging a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24897
diff changeset
10143 delete_instr(dfunc->df_instr_debug + idx);
99324f6b535a patch 8.2.2989: Vim9: memory leak when debugging a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24897
diff changeset
10144 VIM_CLEAR(dfunc->df_instr_debug);
99324f6b535a patch 8.2.2989: Vim9: memory leak when debugging a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24897
diff changeset
10145 dfunc->df_instr_debug = NULL;
99324f6b535a patch 8.2.2989: Vim9: memory leak when debugging a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24897
diff changeset
10146 }
23729
7eef04861034 patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 23725
diff changeset
10147 #ifdef FEAT_PROFILE
7eef04861034 patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 23725
diff changeset
10148 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
10149 {
7eef04861034 patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 23725
diff changeset
10150 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
10151 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
10152 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
10153 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
10154 }
7eef04861034 patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 23725
diff changeset
10155 #endif
23360
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
10156
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
10157 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
10158 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
10159 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
10160 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
10161 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
10162
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
10163 /*
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
10164 * 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
10165 * 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
10166 * 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
10167 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10168 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
10169 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
10170 {
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
10171 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
10172 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10173 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
10174 + 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
10175
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
10176 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
10177 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
10178 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
10179 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
10180 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
10181 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
10182 }
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
10183 }
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
10184
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
10185 /*
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
10186 * 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
10187 */
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
10188 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
10189 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
10190 {
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
10191 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
10192 {
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
10193 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
10194 + 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
10195
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
10196 ++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
10197 }
22324
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
10198 }
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
10199
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10200 #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
10201 /*
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
10202 * 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
10203 */
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10204 void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10205 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
10206 {
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
10207 int idx;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
10208
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
10209 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
10210 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
10211 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
10212
23360
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
10213 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
10214 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
10215 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
10216
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
10217 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
10218 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10219 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10220
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10221
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10222 #endif // FEAT_EVAL