annotate src/vim9compile.c @ 24498:bfa495227ac6 v8.2.2789

patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps Commit: https://github.com/vim/vim/commit/8238f08838c0b481d0b14a741bc03f2e45c211d3 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Apr 20 21:10:48 2021 +0200 patch 8.2.2789: Vim9: using \=expr in :substitute does not handle jumps Problem: Vim9: using \=expr in :substitute does not handle jumps. Solution: Start with instruction count zero. (closes https://github.com/vim/vim/issues/8128)
author Bram Moolenaar <Bram@vim.org>
date Tue, 20 Apr 2021 21:15:04 +0200
parents cca0a1b4e878
children 5baac0b4b41c
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
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
137 char_u *lhs_name; // allocated name including
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"
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
141 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
142 // "[expr]" or ".name".
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
143
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
144 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
145
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
146 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
147 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
148 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
149
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
150 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
151 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
152 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
153 int lhs_scriptvar_sid;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
154 int lhs_scriptvar_idx;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
155
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
156 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
157 type_T *lhs_type;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
158 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
159
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
160 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
161 } lhs_T;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
162
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 * 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
165 * 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
166 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 struct cctx_S {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 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
169 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
170 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
171 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
172
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
173 int ctx_profiling; // when TRUE generate ISN_PROF_START
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
174
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_locals; // currently visible local variables
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
176 int ctx_locals_count; // total number of local variables
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22369
diff changeset
178 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
179 // the function
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
180
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 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
182
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
183 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
184 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
185 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
186
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
187 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
188 // function
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
189 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
190
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 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
192 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
193
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
194 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
195
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
196 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
197 // 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
198 };
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199
23360
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
200 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
201
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 /*
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
203 * 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
204 * "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
205 * 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
206 * 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
207 */
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
208 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
209 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
210 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 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
212 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
213
19392
5b6f420e7352 patch 8.2.0254: compiler warning for checking size_t to be negative
Bram Moolenaar <Bram@vim.org>
parents: 19388
diff changeset
214 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
215 return FAIL;
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
216
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
217 // 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
218 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
219 {
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
220 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
221 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
222 && 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
223 {
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
224 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
225 {
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
226 *lvar = *lvp;
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
227 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
228 }
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
229 return OK;
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
230 }
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
231 }
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
232
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
233 // 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
234 if (cctx->ctx_outer != NULL)
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
235 {
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
236 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
237 {
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
238 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
239 {
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
240 cctx->ctx_outer_used = TRUE;
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
241 ++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
242 }
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
243 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
244 }
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
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
247 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 /*
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
251 * 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
252 * 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
253 * 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
254 * 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
255 * 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
256 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 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
258 arg_exists(
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
259 char_u *name,
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
260 size_t len,
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
261 int *idxp,
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
262 type_T **type,
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
263 int *gen_load_outer,
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
264 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
265 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 int idx;
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
267 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
268
19392
5b6f420e7352 patch 8.2.0254: compiler warning for checking size_t to be negative
Bram Moolenaar <Bram@vim.org>
parents: 19388
diff changeset
269 if (len == 0)
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
270 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 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
272 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 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
274
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
275 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
276 {
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
277 if (idxp != NULL)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
278 {
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
279 // 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
280 // 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
281 *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
282 + STACK_FRAME_SIZE)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
283 + (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
284
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
285 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
286 *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
287 else
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
288 *type = &t_any;
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
289 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
290 return OK;
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
291 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
292 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
293
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
294 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
295 if (va_name != NULL
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
296 && 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
297 {
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
298 if (idxp != NULL)
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 // 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
301 *idxp = -STACK_FRAME_SIZE - 1;
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
302 *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
303 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
304 return OK;
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
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
307 if (cctx->ctx_outer != NULL)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
308 {
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
309 // 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
310 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
311 == OK)
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
312 {
23923
be36288235af patch 8.2.2504: Vim9: crash when using an argument from a closure
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
313 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
314 ++*gen_load_outer;
20275
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
315 return OK;
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
316 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
317 }
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
318
350bb78345ba patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents: 20259
diff changeset
319 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 /*
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
323 * 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
324 * 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
325 * "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
326 * 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
327 * 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
328 */
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
329 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
330 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
331 {
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
332 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
333 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
334 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
335 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
336 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
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 // 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
339 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
340 {
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
341 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
342 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
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 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
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 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
347 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
348 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
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 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
351 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
352 // 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
353 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
354
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
355 // 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
356 // 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
357 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
358 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
359 {
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
360 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
361
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
362 // 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
363 // 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
364 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
365 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
366 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
367 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
368 }
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
369
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
370 return NULL;
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
371 }
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
372
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
373 /*
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 23199
diff changeset
374 * 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
375 */
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
376 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
377 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
378 {
8e09827f8bac patch 8.2.1515: Vim9: can create s:var in legacy script but cannot unlet
Bram Moolenaar <Bram@vim.org>
parents: 21921
diff changeset
379 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
380 }
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 /*
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
383 * 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
384 * "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
385 * 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
386 */
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
387 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
388 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
389 {
22381
6fe9536694ff patch 8.2.1739: Vim9: crash when compiling a manually defined function
Bram Moolenaar <Bram@vim.org>
parents: 22371
diff changeset
390 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
391 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
392 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
393 {
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
394 // 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
395 // defined.
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
396 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
397 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
398 }
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
399 else
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
400 {
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
401 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
402 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
403 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
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 // 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
406 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
407 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
408 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
409 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
410 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
411 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
412 }
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
413
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
414 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416
19623
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
417 /*
23966
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
418 * 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
419 * imported.
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
420 */
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
421 static int
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
422 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
423 {
24033
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
424 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
425 && (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
426 || 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
427 || 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
428 || 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
429 }
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
430
09bde146adcb patch 8.2.2525: Vim9: only local variables checked for a name
Bram Moolenaar <Bram@vim.org>
parents: 23948
diff changeset
431 /*
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
432 * 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
433 * 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
434 */
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
435 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
436 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
437 {
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 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
439 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
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 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
442 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
443
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
444 // 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
445 // 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
446 // 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
447 // 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
448 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
449
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 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
451 {
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 // Do not check for an internal function, since it might also be a
f4061617c438 patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents: 24116
diff changeset
453 // valid command, such as ":split" versuse "split()".
f4061617c438 patch 8.2.2603: Vim9: no effect if user command is also a function
Bram Moolenaar <Bram@vim.org>
parents: 24116
diff changeset
454 // 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
455 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
456 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
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 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
459 }
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
460
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
461 /*
19623
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
462 * 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
463 * 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
464 * 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
465 * 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
466 * 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
467 */
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
468 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
469 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
470 {
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
471 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
472 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
473
24420
e0fa539a9b34 patch 8.2.2750: Vim9: error for using underscore in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24408
diff changeset
474 // 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
475 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
476 return OK;
e0fa539a9b34 patch 8.2.2750: Vim9: error for using underscore in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24408
diff changeset
477
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
478 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
479 {
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
480 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
481 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
482 else
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
483 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
484 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
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
21604
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
487 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
488 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
489 && (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
490 || 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
491 || 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
492 || (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
493 {
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
494 // A local or script-local function can shadow a global function.
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
495 if (ufunc == NULL || !func_is_global(ufunc)
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
496 || (p[0] == 'g' && p[1] == ':'))
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
497 {
24033
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
498 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
499 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
500 else
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
501 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
502 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
503 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
504 }
19623
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
505 }
21604
d9c45474cac1 patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents: 21602
diff changeset
506 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
507 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
508 }
2fee087c94cb patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents: 19597
diff changeset
509
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
510
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 /////////////////////////////////////////////////////////////////////
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 // 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
513
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
514 #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
515 #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
516
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 * 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
519 * 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
520 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 static isn_T *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 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
523 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 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
525 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
527 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
528 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
529 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 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
531 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
532 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
533 ++instr->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 return isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 * 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
540 * "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
541 * 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
542 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 static isn_T *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 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
545 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 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
547
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
548 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
549 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
550 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
551 }
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 * 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
555 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 static isn_T *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 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
558 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 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
561
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 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
563 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 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
566 return NULL;
21473
8bcd1ee2630b patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
567 ((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
568 ++stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 return isn;
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
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 * 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
575 * But only for simple types.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 may_generate_2STRING(int offset, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 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
581 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
582 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
583 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
584
4cd173b3d572 patch 8.2.2330: Vim9: crash when using :trow in a not executed block
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
585 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
586 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
587 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
588 {
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
589 // 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
590 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
591
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
592 // 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
593 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
594 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
595 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
596 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
597 break;
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
598
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
599 // 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
600 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
601 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
602 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
603 break;
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
604
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
605 // 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
606 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
607 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
608 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
609 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
610 case VAR_LIST:
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
611 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
612 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
613 case VAR_CHANNEL:
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21769
diff changeset
614 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
615 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
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
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 *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
619 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
620 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 isn->isn_arg.number = offset;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 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
628 {
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
629 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
630 && (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
631 || 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
632 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 if (*op == '+')
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
634 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
635 else
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
636 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
637 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
642 static int
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
643 generate_add_instr(
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
644 cctx_T *cctx,
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
645 vartype_T vartype,
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
646 type_T *type1,
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
647 type_T *type2)
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
648 {
23199
59f31d2eb4cf patch 8.2.2145: Vim9: concatenating lists does not adjust type of result
Bram Moolenaar <Bram@vim.org>
parents: 23195
diff changeset
649 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
650 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
651 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
652 : 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
653 : 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
654 #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
655 : 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
656 #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
657 : ISN_OPANY, 1);
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
658
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
659 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
660 && type1->tt_type != VAR_ANY
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
661 && type2->tt_type != VAR_ANY
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
662 && check_number_or_float(
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
663 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
664 return FAIL;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
665
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
666 if (isn != NULL)
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
667 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
668
59f31d2eb4cf patch 8.2.2145: Vim9: concatenating lists does not adjust type of result
Bram Moolenaar <Bram@vim.org>
parents: 23195
diff changeset
669 // 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
670 // 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
671 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
672 && 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
673 && 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
674 (((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
675
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
676 return isn == NULL ? FAIL : OK;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
677 }
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
678
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
679 /*
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
680 * 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
681 * "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
682 * 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
683 */
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
684 static vartype_T
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
685 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
686 {
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
687 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
688 && (type1->tt_type == VAR_NUMBER
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
689 || type1->tt_type == VAR_LIST
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
690 #ifdef FEAT_FLOAT
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
691 || type1->tt_type == VAR_FLOAT
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
692 #endif
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
693 || type1->tt_type == VAR_BLOB))
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
694 return type1->tt_type;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
695 return VAR_ANY;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
696 }
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
697
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 * 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
700 * 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
701 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 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
704 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 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
706 type_T *type1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 type_T *type2;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 vartype_T vartype;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
711 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
712
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
713 // 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
714 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
715 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
716 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
717
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 switch (*op)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 {
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
720 case '+':
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
721 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
722 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 case '-':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 case '*':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 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
728 op) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 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
731 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
732 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 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
734 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
735 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 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
738 if (isn != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 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
740 ? 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
741 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
743 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
744 && 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
745 || (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
746 && 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
747 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
748 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
749 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 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
752 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
753 if (isn != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 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
755 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 // 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
759 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
760 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 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
762
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 // 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
765 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
766 && (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
767 type = &t_float;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 ((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
770 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 /*
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
776 * 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
777 * 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
778 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
779 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
780 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
781 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 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
783
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
784 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
785 type1 = VAR_ANY;
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
786 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
787 type2 = VAR_ANY;
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
788
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 if (type1 == type2)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 switch (type1)
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 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
794 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
795 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
796 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
797 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
798 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
799 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
800 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
801 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
802 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
803 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 }
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19918
diff changeset
805 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
806 || ((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
807 && (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
808 isntype = ISN_COMPAREANY;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
810 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
811 && (isntype == ISN_COMPAREBOOL
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 || isntype == ISN_COMPARESPECIAL
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 || isntype == ISN_COMPARENR
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 || isntype == ISN_COMPAREFLOAT))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
816 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
817 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
818 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
819 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 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
821 || ((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
822 && (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
823 || 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
824 || ((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
825 && 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
826 && (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
827 || 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
828 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
829 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
830 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
831 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
832 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
833 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
834 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
835
21251
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
836 int
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
837 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
838 {
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
839 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
840 return FAIL;
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
841 return OK;
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
842 }
d1215fcdbca8 patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 21248
diff changeset
843
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
844 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
845 * 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
846 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
847 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
848 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
849 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
850 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
851 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
852 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
853 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
854 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
855
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
856 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
857
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
858 // 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
859 // 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
860 // checking.
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
861 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
862 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
863 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
864 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
865 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 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
868 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
869 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
870 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
871
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 // 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
873 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
874 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 --stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 ((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
877 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 * Generate an ISN_2BOOL instruction.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 generate_2BOOL(cctx_T *cctx, int invert)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 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
890
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
891 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
892 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
893 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 isn->isn_arg.number = invert;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 // type becomes bool
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 ((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
898
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
902 /*
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
903 * 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
904 */
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
905 static int
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
906 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
907 {
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
908 isn_T *isn;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
909 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
910
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
911 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
912 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
913 return FAIL;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
914
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
915 // type becomes bool
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
916 ((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
917
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
918 return OK;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
919 }
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
920
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 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
922 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
923 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
924 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
925 int offset,
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
926 int argidx)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 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
930
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
931 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
932 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
933 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
934 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
935 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
936 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
937
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
938 // 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
939 ((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
940
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943
23458
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
944 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
945 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
946 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
947 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
948 {
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
949 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
950
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
951 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
952 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
953 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
954 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
955 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
956 }
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
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 /*
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
959 * 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
960 * 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
961 */
22898
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22860
diff changeset
962 int
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
963 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
964 {
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
965 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
966 || 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
967 || (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
968 && (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
969 || 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
970 && (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
971 && ((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
972 == (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
973 return TRUE;
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
974 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
975 && 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
976 // 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
977 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
978 return FALSE;
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
979 }
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
980
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
981 /*
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
982 * 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
983 * - "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
984 * - "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
985 * - return FAIL.
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
986 * 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
987 * generate a TYPECHECK.
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
988 */
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
989 int
21265
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21255
diff changeset
990 need_type(
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21255
diff changeset
991 type_T *actual,
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21255
diff changeset
992 type_T *expected,
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21255
diff changeset
993 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
994 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
995 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
996 int silent,
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
997 int actual_is_const)
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
998 {
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
999 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
1000
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
1001 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
1002 && (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
1003 {
d835f2fdfcfc patch 8.2.1647: Vim9: result of expression with && and || is not a bool
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
1004 // 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
1005 // boolean is OK but requires a conversion.
d835f2fdfcfc patch 8.2.1647: Vim9: result of expression with && and || is not a bool
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
1006 generate_2BOOL(cctx, FALSE);
d835f2fdfcfc patch 8.2.1647: Vim9: result of expression with && and || is not a bool
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
1007 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
1008 }
d835f2fdfcfc patch 8.2.1647: Vim9: result of expression with && and || is not a bool
Bram Moolenaar <Bram@vim.org>
parents: 22184
diff changeset
1009
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23888
diff changeset
1010 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
1011 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
1012 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
1013 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
1014
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
1015 // 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
1016 // 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
1017 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
1018 {
23691
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
1019 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
1020 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
1021 }
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
1022
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22276
diff changeset
1023 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
1024 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
1025 return FAIL;
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
1026 }
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
1027
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
1028 /*
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
1029 * 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
1030 * 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
1031 */
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
1032 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
1033 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
1034 {
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
1035 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
1036 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
1037
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
1038 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
1039 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
1040 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
1041
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
1042 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
1043 // 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
1044 // 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
1045 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
1046
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
1047 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
1048 }
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
1049
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22842
diff changeset
1050 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 * 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
1052 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 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
1055 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 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
1057 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
1058
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1059 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
1060 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
1061 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 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
1063
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
1064 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
1065 // 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
1066 ((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
1067 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 * 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
1072 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 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
1075 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1078 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
1079 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
1080 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 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
1082
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 * 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
1088 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 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
1091 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1094 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
1095 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
1096 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 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
1098
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 * 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
1105 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 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
1108 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1111 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
1112 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
1113 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 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
1115
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 #endif
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 * 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
1122 * Consumes "str".
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 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 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
1126 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128
23473
ad83c0ff34c0 patch 8.2.2279: Vim9: memory leak with catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23458
diff changeset
1129 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
1130 {
ad83c0ff34c0 patch 8.2.2279: Vim9: memory leak with catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23458
diff changeset
1131 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
1132 return OK;
ad83c0ff34c0 patch 8.2.2279: Vim9: memory leak with catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23458
diff changeset
1133 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 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
1135 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 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
1137
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 }
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 /*
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1142 * 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
1143 * Consumes "channel".
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1144 */
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1145 static int
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1146 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
1147 {
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1148 isn_T *isn;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1149
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1150 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
1151 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
1152 return FAIL;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1153 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
1154
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1155 return OK;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1156 }
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1157
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1158 /*
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1159 * 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
1160 * Consumes "job".
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1161 */
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1162 static int
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1163 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
1164 {
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1165 isn_T *isn;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1166
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1167 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
1168 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
1169 return FAIL;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1170 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
1171
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1172 return OK;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1173 }
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1174
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1175 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 * 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
1177 * Consumes "blob".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180 generate_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
1181 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1184 RETURN_OK_IF_SKIP(cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 if ((isn = generate_instr_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
1186 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 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
1188
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 /*
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1193 * 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
1194 * Consumes "name".
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 static int
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
1197 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
1198 {
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1199 isn_T *isn;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1200
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1201 RETURN_OK_IF_SKIP(cctx);
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
1202 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
1203 return FAIL;
21473
8bcd1ee2630b patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
1204 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
1205
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1206 return OK;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
1207 }
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 /*
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1210 * Generate an ISN_GETITEM instruction with "index".
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1211 */
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1212 static int
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1213 generate_GETITEM(cctx_T *cctx, int index)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1214 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1215 isn_T *isn;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1216 garray_T *stack = &cctx->ctx_type_stack;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1217 type_T *type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1218 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
1219
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1220 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
1221
21421
0f0fee4122d3 patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents: 21411
diff changeset
1222 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
1223 {
0f0fee4122d3 patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents: 21411
diff changeset
1224 // 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
1225 emsg(_(e_listreq));
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1226 return FAIL;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1227 }
21421
0f0fee4122d3 patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents: 21411
diff changeset
1228 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
1229 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
1230 return FAIL;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1231 isn->isn_arg.number = index;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1232
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1233 // 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
1234 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
1235 return FAIL;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1236 ((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
1237 ++stack->ga_len;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1238 return OK;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1239 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1240
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
1241 /*
20871
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1242 * 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
1243 */
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1244 static int
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1245 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
1246 {
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1247 isn_T *isn;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1248
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1249 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
1250 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
1251 return FAIL;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1252 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
1253 return OK;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1254 }
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1255
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1256 /*
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1257 * 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
1258 */
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1259 static int
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1260 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
1261 {
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1262 isn_T *isn;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1263
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1264 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
1265
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1266 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
1267 return FAIL;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1268 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
1269 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
1270
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1271 return OK;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1272 }
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1273
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
1274 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 * 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
1276 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 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
1279 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1282 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
1283 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
1284 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 if (name != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286 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
1287 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288 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
1289
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 /*
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1294 * Generate an ISN_STOREOUTER instruction.
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1295 */
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1296 static int
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1297 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
1298 {
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1299 isn_T *isn;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1300
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1301 RETURN_OK_IF_SKIP(cctx);
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1302 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
1303 return FAIL;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1304 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
1305 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
1306
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1307 return OK;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1308 }
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1309
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1310 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1311 * 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
1312 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1313 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314 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
1315 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1317
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1318 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
1319 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
1320 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
1321 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
1322 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
1323
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1324 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328 * 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
1329 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 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
1332 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1335 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
1336 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
1337 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1338 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
1339 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
1340
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1341 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1342 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1343
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1344 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 * 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
1346 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1347 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348 generate_LOAD(
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1349 cctx_T *cctx,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1350 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
1351 int idx,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 char_u *name,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1353 type_T *type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1356
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1357 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
1358 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
1359 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1360 if (name != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 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
1362 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363 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
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 /*
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1369 * Generate an ISN_LOADOUTER instruction
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1370 */
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1371 static int
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1372 generate_LOADOUTER(
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1373 cctx_T *cctx,
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1374 int idx,
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1375 int nesting,
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1376 type_T *type)
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1377 {
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1378 isn_T *isn;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1379
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1380 RETURN_OK_IF_SKIP(cctx);
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1381 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
1382 return FAIL;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1383 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
1384 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
1385
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1386 return OK;
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1387 }
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1388
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1389 /*
19960
3c11b9f6fa03 patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1390 * 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
1391 */
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1392 static int
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1393 generate_LOADV(
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1394 cctx_T *cctx,
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1395 char_u *name,
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1396 int error)
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1397 {
19960
3c11b9f6fa03 patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1398 int di_flags;
3c11b9f6fa03 patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1399 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
1400 type_T *type;
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1401
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1402 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
1403 if (vidx < 0)
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1404 {
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1405 if (error)
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
1406 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
1407 return FAIL;
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1408 }
21443
66386ca8a69f patch 8.2.1272: Vim9: type not checked if declaration also assigns value
Bram Moolenaar <Bram@vim.org>
parents: 21441
diff changeset
1409 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
1410
3c11b9f6fa03 patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents: 19946
diff changeset
1411 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
1412 }
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1413
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1414 /*
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1415 * Generate an ISN_UNLET instruction.
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1416 */
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1417 static int
20099
058b41f85bcb patch 8.2.0605: Vim9: cannot unlet an environment variable
Bram Moolenaar <Bram@vim.org>
parents: 20091
diff changeset
1418 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
1419 {
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1420 isn_T *isn;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1421
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1422 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
1423 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
1424 return FAIL;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1425 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
1426 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
1427
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1428 return OK;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1429 }
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1430
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
1431 /*
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1432 * 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
1433 */
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1434 static int
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1435 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
1436 {
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1437 isn_T *isn;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1438
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1439 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
1440 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
1441 return FAIL;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1442 return OK;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1443 }
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1444
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
1445 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1446 * 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
1447 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1448 static int
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1449 generate_OLDSCRIPT(
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1450 cctx_T *cctx,
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1451 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
1452 char_u *name,
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1453 int sid,
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1454 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
1455 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1456 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1457
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1458 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
1459 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
1460 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
1461 else
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1462 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
1463 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
1464 return FAIL;
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1465 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
1466 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
1467
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1468 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1469 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1470
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1471 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1472 * 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
1473 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474 static int
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
1475 generate_VIM9SCRIPT(
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1476 cctx_T *cctx,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477 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
1478 int sid,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479 int idx,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1480 type_T *type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1482 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
1483 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
1484 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
1485
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1486 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
1487 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
1488 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
1489 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1490 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
1491 if (isn == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1492 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
1493
e8eb4fd44902 patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents: 23318
diff changeset
1494 // 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
1495 // 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
1496 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
1497 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
1498 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
1499 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
1500 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
1501 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
1502 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
1503 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
1504 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1505 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1506
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1507 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 * 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
1509 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1511 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
1512 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1514 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
1515 type_T *type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1516 type_T *member;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1517
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1518 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
1519 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
1520 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521 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
1522
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
1523 // 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
1524 if (count == 0)
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1525 member = &t_void;
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1526 else
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1527 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
1528 ((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
1529 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
1530 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
1531
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1532 // 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
1533 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
1534
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1535 // 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
1536 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
1537 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 ((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
1539 ++stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1541 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1542 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1543
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1544 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1545 * 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
1546 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1548 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
1549 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551 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
1552 type_T *type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1553 type_T *member;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1555 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
1556 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
1557 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558 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
1559
22021
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1560 if (count == 0)
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1561 member = &t_void;
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1562 else
514d622473af patch 8.2.1560: using NULL pointers in some code
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
1563 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
1564 ((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
1565 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
1566 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
1567
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1568 // 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
1569 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
1570
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1571 // 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
1572 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
1573 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574 ((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
1575 ++stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1577 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1578 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1579
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1580 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581 * 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
1582 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1583 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
1584 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
1585 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1586 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1587 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
1588
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1589 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
1590 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
1591 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
1592 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
1593 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
1594
24158
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
1595 // 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
1596 // the nested context, including this one.
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1597 if (ufunc->uf_flags & FC_CLOSURE)
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
1598 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
1599
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1600 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
1601 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
1602 ((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
1603 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
1604 ++stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1605
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1606 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1607 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1608
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1609 /*
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1610 * 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
1611 * "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
1612 * consumed.
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1613 */
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1614 static int
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1615 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
1616 {
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1617 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
1618
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1619 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
1620 {
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1621 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
1622 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
1623 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
1624 }
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1625 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
1626 {
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1627 vim_free(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
1628 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
1629 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
1630 }
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
1631 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
1632 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
1633
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1634 return OK;
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1635 }
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1636
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
1637 /*
22973
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1638 * 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
1639 */
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1640 static int
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1641 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
1642 {
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1643 isn_T *isn;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1644
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1645 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
1646 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
1647 return FAIL;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1648 if (len > 0)
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1649 {
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1650 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
1651 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
1652 return FAIL;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1653 }
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1654 return OK;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1655 }
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1656
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
1657 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 * 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
1659 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1660 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1661 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
1662 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1663 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1664 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
1665
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1666 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
1667 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
1668 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669 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
1670 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
1671
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1672 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
1673 --stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1674
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1676 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677
24272
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1678 /*
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1679 * 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
1680 */
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1681 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
1682 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
1683 {
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1684 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
1685
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1686 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
1687 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
1688 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
1689 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
1690 // 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
1691 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
1692 }
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1693
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1694 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1695 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
1696 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1697 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1698 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
1699
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1700 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
1701 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
1702 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1703 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
1704
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1705 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
1706 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1707 // 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
1708 ((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
1709 ++stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1710
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1711 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1712 }
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
1713 /*
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1714 * 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
1715 */
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1716 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
1717 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
1718 {
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1719 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
1720
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1721 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
1722 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
1723 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
1724 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
1725 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
1726
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1727 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
1728 }
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
1729
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1730
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1731 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1732 * 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
1733 * "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
1734 * 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
1735 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1736 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
1737 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
1738 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1739 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1740 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
1741 int argoff;
22671
ad54acb1bf2c patch 8.2.1884: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents: 22667
diff changeset
1742 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
1743 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
1744
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1745 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
1746 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
1747 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
1748 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1749
21232
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
1750 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
1751 {
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
1752 if ((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
1753 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
1754 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
1755 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
1756 }
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21220
diff changeset
1757
22663
0f90c15a4a28 patch 8.2.1880: Vim9: asan complains about adding zero to NULL
Bram Moolenaar <Bram@vim.org>
parents: 22661
diff changeset
1758 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
1759 {
0f90c15a4a28 patch 8.2.1880: Vim9: asan complains about adding zero to NULL
Bram Moolenaar <Bram@vim.org>
parents: 22661
diff changeset
1760 // 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
1761 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
1762 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
1763 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
1764 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
1765 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
1766 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
1767 }
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22639
diff changeset
1768
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1769 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
1770 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1771 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
1772 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
1773
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22639
diff changeset
1774 // 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
1775 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
1776 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
1777 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1778 ((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
1779 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
1780 ++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
1781
23565
34aa2907082a patch 8.2.2325: Vim9: crash if map() changes the item type
Bram Moolenaar <Bram@vim.org>
parents: 23561
diff changeset
1782 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
1783 && 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
1784 // 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
1785 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
1786
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1787 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1788 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1789
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1790 /*
22633
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1791 * 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
1792 * 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
1793 */
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1794 static int
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1795 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
1796 {
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1797 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
1798 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
1799 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
1800 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
1801
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1802 // 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
1803 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
1804 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
1805 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
1806 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
1807 return FAIL;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1808
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1809 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
1810 return FAIL;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1811
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1812 --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
1813 return OK;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1814 }
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1815
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
1816 /*
22637
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1817 * 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
1818 * 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
1819 */
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1820 static int
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1821 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
1822 {
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1823 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
1824 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
1825
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1826 // 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
1827 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
1828 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
1829 return FAIL;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1830
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1831 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
1832 return FAIL;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1833
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1834 --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
1835 return OK;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1836 }
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1837
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
1838 /*
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1839 * 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
1840 * "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
1841 */
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1842 int
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
1843 func_needs_compiling(ufunc_T *ufunc, int profile UNUSED)
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1844 {
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1845 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
1846 {
24404
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
1847 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
1848 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
1849
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1850 case UF_COMPILED:
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1851 {
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
1852 #ifdef FEAT_PROFILE
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1853 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
1854 + ufunc->uf_dfunc_idx;
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1855
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1856 return profile ? dfunc->df_instr_prof == NULL
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1857 : dfunc->df_instr == NULL;
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
1858 #else
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
1859 break;
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
1860 #endif
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
1861 }
24404
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
1862
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
1863 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
1864 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
1865 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
1866 break;
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
1867 }
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
1868 return FALSE;
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1869 }
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1870
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1871 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1872 * 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
1873 * 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
1874 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1875 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
1876 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
1877 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1878 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1879 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
1880 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
1881 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
1882
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1883 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
1884 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
1885 {
22318
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22292
diff changeset
1886 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
1887 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1888 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1889 if (argcount < regular_args - 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
1890 {
22318
3f5f96a8dd83 patch 8.2.1708: Vim9: error message for function has unpritable characters
Bram Moolenaar <Bram@vim.org>
parents: 22292
diff changeset
1891 semsg(_(e_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
1892 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1893 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1894
24404
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
1895 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
1896 && 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
1897 {
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1898 int i;
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1899
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1900 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
1901 {
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1902 type_T *expected;
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1903 type_T *actual;
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1904
24272
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1905 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
1906 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
1907 && 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
1908 {
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1909 // 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
1910 continue;
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
1911 }
19944
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1912 if (i < regular_args)
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1913 {
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1914 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
1915 continue;
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1916 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
1917 }
24400
62e978382fa0 patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24390
diff changeset
1918 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
1919 || 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
1920 // 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
1921 expected = &t_any;
19944
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1922 else
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1923 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
1924 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
1925 TRUE, FALSE) == FAIL)
19944
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1926 {
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1927 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
1928 return FAIL;
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1929 }
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1930 }
23735
7caffd835aa1 patch 8.2.2409: Vim9: profiling only works for one function
Bram Moolenaar <Bram@vim.org>
parents: 23729
diff changeset
1931 if (func_needs_compiling(ufunc, PROFILING(ufunc))
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1932 && compile_def_function(ufunc, ufunc->uf_ret_type == NULL,
23735
7caffd835aa1 patch 8.2.2409: Vim9: profiling only works for one function
Bram Moolenaar <Bram@vim.org>
parents: 23729
diff changeset
1933 PROFILING(ufunc), NULL) == FAIL)
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1934 return FAIL;
19944
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1935 }
3055cd26e139 patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19942
diff changeset
1936
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1937 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
1938 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
1939 : 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
1940 return FAIL;
22326
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
1941 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
1942 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1943 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
1944 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
1945 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1946 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1947 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1948 // 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
1949 // 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
1950 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
1951 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
1952 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1953
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1954 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
1955 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
1956 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1957 // add return value
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958 ((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
1959 ++stack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1960
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1961 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1962 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1963
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1964 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1965 * 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
1966 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1967 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1968 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
1969 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1970 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1971 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
1972
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
1973 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
1974 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
1975 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1976 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
1977 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
1978
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1979 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
1980 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
1981 return FAIL;
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
1982 // add return value
2a63b7f5802a patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
1983 ((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
1984 ++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
1985
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1986 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1987 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1988
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1989 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1990 * 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
1991 * "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
1992 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1993 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
1994 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
1995 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
1996 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
1997 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
1998 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
1999 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
2000 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2001 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2002 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
2003 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
2004
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
2005 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
2006
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
2007 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
2008 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
2009 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
2010 {
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
2011 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
2012 {
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
2013 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
2014
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
2015 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
2016 {
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
2017 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
2018 return FAIL;
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
2019 }
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
2020 if (!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
2021 {
22734
02b782e80ee4 patch 8.2.1915: Vim9: error for wrong number of arguments is not useful
Bram Moolenaar <Bram@vim.org>
parents: 22703
diff changeset
2022 semsg(_(e_toomanyarg), name);
20281
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
2023 return FAIL;
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
2024 }
22816
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2025 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
2026 {
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2027 int i;
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2028
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2029 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
2030 {
24402
009a540f16a6 patch 8.2.2741: Vim9: Partial call does not check right arguments
Bram Moolenaar <Bram@vim.org>
parents: 24400
diff changeset
2031 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
2032 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
2033 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
2034 type_T *expected;
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2035
23527
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23525
diff changeset
2036 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
2037 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
2038 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
2039 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
2040 && 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
2041 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
2042 else
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2043 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
2044 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
2045 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
2046 {
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2047 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
2048 return FAIL;
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2049 }
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2050 }
8a5369f5f2b4 patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents: 22772
diff changeset
2051 }
20281
ab8c8fd0f868 patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 20279
diff changeset
2052 }
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
2053 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
2054 }
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 else
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
2056 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2057 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
2058 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
2059 }
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
2060
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2061 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
2062 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2063 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
2064 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
2065
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2066 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
2067
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2068 // 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
2069 ((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
2070
19862
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19860
diff changeset
2071 // 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
2072 // the return value.
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19860
diff changeset
2073 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
2074 return FAIL;
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19860
diff changeset
2075
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2076 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2077 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2078
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2079 /*
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
2080 * 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
2081 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2082 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
2083 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
2084 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2085 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2086 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
2087 type_T *type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2088
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
2089 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
2090 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
2091 return FAIL;
20830
9064044fd4f6 patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
2092 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
2093
19461
08ef11a81daa patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
2094 // 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
2095 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
2096 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
2097 {
08ef11a81daa patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
2098 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
2099 return FAIL;
08ef11a81daa patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
2100 }
08ef11a81daa patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
2101 // 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
2102 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
2103 {
647ff61c0bcd patch 8.2.2323: Vim9: error when inferring type from empty dict/list
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2104 ((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
2105 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
2106 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2107
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2108 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2109 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2110
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2111 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2112 * 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
2113 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2114 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2115 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
2116 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2117 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2118
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
2119 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
2120 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
2121 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2122 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
2123 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
2124
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2125 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2126 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2127
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2128 /*
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
2129 * 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
2130 */
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2131 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
2132 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
2133 {
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2134 isn_T *isn;
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2135
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
2136 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
2137 return FAIL;
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2138 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
2139
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2140 return OK;
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2141 }
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
2142
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
2143 /*
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
2144 * 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
2145 */
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
2146 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
2147 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
2148 {
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
2149 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
2150
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
2151 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
2152 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
2153 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
2154 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
2155 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
2156 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
2157 }
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
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 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2160 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
2161 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2162 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2163
19587
e61dc51ab9b4 patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents: 19583
diff changeset
2164 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
2165 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
2166 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2167 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
2168 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2169 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2170
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2171 static int
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2172 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
2173 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2174 isn_T *isn;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2175
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2176 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
2177 return FAIL;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2178 isn->isn_arg.number = count;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2179 return OK;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2180 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
2181
23156
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2182 /*
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2183 * 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
2184 */
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2185 static int
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2186 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
2187 {
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2188 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
2189 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
2190
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2191 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
2192 return FAIL;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2193 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
2194
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2195 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
2196 return FAIL;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2197 ((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
2198 ++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
2199 return OK;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2200 }
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
2201
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2202 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
2203 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
2204 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2205 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
2206
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2207 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
2208 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
2209 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
2210 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
2211 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
2212 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
2213 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
2214
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2215 /*
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
2216 * 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
2217 */
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2218 static int
22699
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 22697
diff changeset
2219 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
2220 {
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2221 isn_T *isn;
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2222
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
2223 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
2224 {
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
2225 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
2226
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
2227 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
2228 return FAIL;
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
2229 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
2230 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
2231 return FAIL;
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
2232 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
2233 // 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
2234 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
2235 }
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
2236
22691
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2237 return OK;
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2238 }
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2239
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2240 static int
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
2241 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
2242 {
23100
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23088
diff changeset
2243 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
2244 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
2245 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
2246 return OK;
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2247 }
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2248
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
2249 static int
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
2250 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
2251 {
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2252 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
2253
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2254 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
2255 && ((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
2256 == ISN_CMDMOD)
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2257 {
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
2258 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
2259 return TRUE;
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
2260 }
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
2261 return FALSE;
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2262 }
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2263
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2264 /*
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2265 * 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
2266 * 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
2267 */
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2268 static int
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2269 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
2270 {
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2271 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
2272 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
2273
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2274 if (cctx->ctx_has_cmdmod && ((isn_T *)instr->ga_data)[idx - 1]
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2275 .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
2276 --idx;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2277 #ifdef FEAT_PROFILE
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2278 if (cctx->ctx_profiling && ((isn_T *)instr->ga_data)[idx - 1]
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2279 .isn_type == ISN_PROF_START)
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2280 --idx;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2281 #endif
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2282 return idx;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2283 }
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
2284
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
2285 #ifdef FEAT_PROFILE
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
2286 static void
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
2287 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
2288 {
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
2289 if (cctx->ctx_profiling && prof_lnum >= 0)
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
2290 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
2291 }
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
2292 #endif
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
2293
22691
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
2294 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2295 * 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
2296 * 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
2297 */
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2298 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
2299 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
2300 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
2301 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
2302 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
2303 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
2304 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
2305 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2306 lvar_T *lvar;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2307
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2308 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
2309 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2310 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
2311 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2312 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2313
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2314 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
2315 return NULL;
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2316 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
2317 CLEAR_POINTER(lvar);
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2318
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2319 // 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
2320 // 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
2321 // 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
2322 // entries. This is less efficient, but memory is cheap these days.
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2323 lvar->lv_idx = cctx->ctx_locals_count++;
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2324
20830
9064044fd4f6 patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
2325 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
2326 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
2327 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
2328
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2329 return lvar;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2330 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2331
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2332 /*
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2333 * 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
2334 */
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2335 static void
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2336 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
2337 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2338 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
2339 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2340 int idx;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2341 lvar_T *lvar;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2342
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2343 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
2344 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2345 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
2346 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
2347 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2348 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2349 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
2350 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2351
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2352 /*
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2353 * 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
2354 */
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2355 static void
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
2356 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
2357 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2358 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
2359 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
2360 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2361
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2362 /*
23578
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2363 * 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
2364 * 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
2365 * 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
2366 */
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2367 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
2368 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
2369 {
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2370 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
2371 || (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
2372 && 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
2373 {
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2374 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
2375 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
2376 }
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2377 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
2378 }
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2379
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2380 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2381 * 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
2382 * 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
2383 * 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
2384 * 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
2385 * 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
2386 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2387 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
2388 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
2389 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2390 hashtab_T *ht;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2391 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
2392 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
2393 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
2394 int idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2395
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2396 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
2397 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
2398 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
2399 {
22598
c7ef64b85e9b patch 8.2.1847: Vim9: using negative value for unsigned type
Bram Moolenaar <Bram@vim.org>
parents: 22596
diff changeset
2400 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
2401
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2402 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
2403 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
2404 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
2405 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
2406 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
2407 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
2408 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
2409 }
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2410
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2411 // 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
2412 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
2413 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
2414 if (di == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2415 return -2;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2416
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2417 // 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
2418 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
2419 {
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
2420 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
2421 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
2422 {
23578
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
2423 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
2424 return -2;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2425 return idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2426 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2427 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2428 return -1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2429 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2430
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2431 /*
20840
0600ab7b9f09 patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2432 * 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
2433 * NULL.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2434 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2435 imported_T *
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
2436 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
2437 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2438 int idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2439
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2440 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
2441 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2442 if (cctx != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2443 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
2444 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2445 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
2446 + idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2447
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
2448 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
2449 : 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
2450 && 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
2451 return import;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2452 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2453
21699
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2454 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
2455 }
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2456
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2457 imported_T *
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2458 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
2459 {
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2460 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
2461 int idx;
1b96535705a0 patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents: 21693
diff changeset
2462
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2463 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
2464 return NULL;
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2465 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
2466 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
2467 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2468 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
2469
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
2470 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
2471 : 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
2472 && 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
2473 return import;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2474 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2475 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2476 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2477
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2478 /*
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2479 * 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
2480 */
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2481 static void
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2482 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
2483 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2484 int idx;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2485
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2486 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
2487 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2488 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
2489
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2490 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
2491 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2492 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
2493 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2494
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
2495 /*
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2496 * 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
2497 * 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
2498 * 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
2499 */
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
2500 char_u *
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
2501 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
2502 {
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2503 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
2504
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2505 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
2506 {
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2507 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
2508 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
2509
21767
9529a2367d3e patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents: 21763
diff changeset
2510 // 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
2511 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
2512 {
9529a2367d3e patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents: 21763
diff changeset
2513 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
2514 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
2515 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
2516 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
2517 return p;
9529a2367d3e patch 8.2.1433: Vim9: cannot mingle comments in multi-line lambda
Bram Moolenaar <Bram@vim.org>
parents: 21763
diff changeset
2518 }
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2519 }
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2520 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
2521 }
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2522
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2523 /*
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2524 * 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
2525 * 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
2526 * 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
2527 * 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
2528 */
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2529 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
2530 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
2531 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2532 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
2533
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2534 *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
2535 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
2536 {
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
2537 *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
2538 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
2539 return *nextp;
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2540 }
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2541 return p;
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2542 }
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2543
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
2544 /*
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2545 * 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
2546 * 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
2547 * 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
2548 */
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
2549 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
2550 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
2551 {
20059
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20055
diff changeset
2552 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
2553
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2554 do
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2555 {
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2556 ++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
2557 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
2558 {
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20055
diff changeset
2559 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
2560 break;
20059
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20055
diff changeset
2561 }
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2562 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
2563 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
2564 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
2565 } 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
2566 || (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
2567 return line;
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2568 }
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2569
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
2570 /*
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
2571 * 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
2572 * 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
2573 * 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
2574 * 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
2575 */
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2576 static int
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
2577 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
2578 {
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
2579 *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
2580 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
2581 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
2582 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
2583 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
2584 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
2585
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2586 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
2587 return FAIL;
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2588 *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
2589 }
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2590 return OK;
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2591 }
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2592
21248
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2593 /*
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2594 * 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
2595 */
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2596 static int
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2597 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
2598 {
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2599 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
2600 {
23122
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23114
diff changeset
2601 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
2602 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
2603 return FAIL;
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2604 }
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2605 return OK;
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2606 }
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2607
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
2608
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2609 // 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
2610 // 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
2611 // 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
2612 // 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
2613 // 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
2614 // 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
2615 #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
2616 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
2617 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
2618 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
2619 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
2620 // 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
2621 } 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
2622
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
2623 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
2624 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
2625 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
2626
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2627 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2628 * 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
2629 * "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
2630 * 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
2631 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2632 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
2633 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
2634 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2635 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
2636 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2637 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
2638 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2639 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
2640 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2641 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
2642 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
2643 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2644 case VAR_SPECIAL:
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2645 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
2646 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2647 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
2648 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
2649 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2650 #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
2651 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
2652 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
2653 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2654 #endif
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2655 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
2656 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
2657 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
2658 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2659 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
2660 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
2661 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
2662 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2663 default:
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2664 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
2665 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
2666 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
2667 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2668 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
2669 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2670 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
2671 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2672
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2673 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2674 * 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
2675 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2676 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
2677 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
2678 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2679 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
2680 int ret = OK;
20332
a407e243c55c patch 8.2.0721: Vim9: leaking memory when skipping
Bram Moolenaar <Bram@vim.org>
parents: 20328
diff changeset
2681 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
2682
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
2683 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
2684 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
2685 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
2686 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
2687 ppconst->pp_used = 0;
20332
a407e243c55c patch 8.2.0721: Vim9: leaking memory when skipping
Bram Moolenaar <Bram@vim.org>
parents: 20328
diff changeset
2688 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
2689 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
2690 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2691
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2692 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2693 * 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
2694 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2695 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
2696 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
2697 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2698 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
2699
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2700 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
2701 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
2702 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
2703 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
2704
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
2705 /*
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
2706 * Compile getting a member from a list/dict/string/blob. Stack has 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
2707 * indexable value and the 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
2708 */
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
2709 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
2710 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
2711 {
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
2712 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
2713 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
2714 vartype_T vtype;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2715 type_T *valtype;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2716
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2717 // We can index a list and a dict. If we don't know the 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
2718 // we can use the index value 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
2719 // TODO: If we don't know use an instruction to figure it out at
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
2720 // runtime.
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
2721 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
2722 - (is_slice ? 3 : 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
2723 vtype = (*typep)->tt_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
2724 valtype = ((type_T **)stack->ga_data)[stack->ga_len - 1];
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2725 // If the index is a string, the variable must be a 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
2726 if (*typep == &t_any && valtype == &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
2727 vtype = 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
2728 if (vtype == VAR_STRING || vtype == VAR_LIST || vtype == VAR_BLOB)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2729 {
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
2730 if (need_type(valtype, &t_number, -1, 0, cctx, 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
2731 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
2732 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
2733 {
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
2734 valtype = ((type_T **)stack->ga_data)[stack->ga_len - 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
2735 if (need_type(valtype, &t_number, -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
2736 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
2737 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
2738 }
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
2739 }
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2740
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2741 if (vtype == 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
2742 {
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2743 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
2744 {
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
2745 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
2746 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
2747 }
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2748 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
2749 {
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2750 *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
2751 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
2752 // 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
2753 *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
2754 }
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2755 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
2756 {
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2757 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
2758 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
2759 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
2760 *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
2761 }
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2762 if (may_generate_2STRING(-1, cctx) == FAIL)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2763 return FAIL;
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2764 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
2765 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
2766 }
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2767 else if (vtype == 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
2768 {
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2769 *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
2770 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
2771 ? 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
2772 : 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
2773 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
2774 }
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2775 else if (vtype == VAR_BLOB)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2776 {
24432
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2777 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
2778 {
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2779 *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
2780 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
2781 return FAIL;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2782 }
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2783 else
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2784 {
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2785 *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
2786 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
2787 return FAIL;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24430
diff changeset
2788 }
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
2789 }
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
2790 else if (vtype == VAR_LIST || *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
2791 {
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
2792 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
2793 {
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
2794 if (generate_instr_drop(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
2795 vtype == VAR_LIST ? ISN_LISTSLICE : ISN_ANYSLICE,
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2796 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
2797 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
2798 }
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
2799 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
2800 {
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2801 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
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 *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
2804 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
2805 // 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
2806 *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
2807 }
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2808 if (generate_instr_drop(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
2809 vtype == VAR_LIST ? ISN_LISTINDEX : ISN_ANYINDEX, 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
2810 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
2811 }
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2812 }
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
2813 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
2814 {
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 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
2816 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
2817 }
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2818 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
2819 }
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2820
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2821 /*
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2822 * 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
2823 * leading "s:".
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2824 * 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
2825 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2826 static int
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2827 compile_load_scriptvar(
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2828 cctx_T *cctx,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2829 char_u *name, // variable NUL terminated
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2830 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
2831 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
2832 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
2833 {
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2834 scriptitem_T *si;
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2835 int idx;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2836 imported_T *import;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2837
21979
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2838 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
2839 return FAIL;
a98211c3e14e patch 8.2.1539: using invalid script ID causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 21963
diff changeset
2840 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
2841 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
2842 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
2843 {
19451
b26e96f7c12f patch 8.2.0283: Vim9: failing to load script var not tested
Bram Moolenaar <Bram@vim.org>
parents: 19437
diff changeset
2844 // 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
2845 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
2846 &t_any);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2847 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2848 if (idx >= 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2849 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2850 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
2851
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
2852 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
2853 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
2854 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2855 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2856
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19283
diff changeset
2857 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
2858 if (import != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2859 {
23364
17a0e32eefd4 patch 8.2.2225: Vim9: error when using :import in legacy script twice
Bram Moolenaar <Bram@vim.org>
parents: 23362
diff changeset
2860 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
2861 {
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2862 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
2863 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
2864 int cc;
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2865 ufunc_T *ufunc;
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2866 type_T *type;
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2867
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2868 // 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
2869 if (*p != '.')
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2870 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2871 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
2872 return FAIL;
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2873 }
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2874 ++p;
19818
c1c88b333481 patch 8.2.0465: Vim9: dead code and wrong return type
Bram Moolenaar <Bram@vim.org>
parents: 19785
diff changeset
2875 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
2876 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2877 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
2878 return FAIL;
c1c88b333481 patch 8.2.0465: Vim9: dead code and wrong return type
Bram Moolenaar <Bram@vim.org>
parents: 19785
diff changeset
2879 }
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2880
21146
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2881 // 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
2882 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
2883 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
2884 ++p;
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2885 cc = *p;
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2886 *p = NUL;
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2887
24116
a028cb6898a2 patch 8.2.2599: build failure
Bram Moolenaar <Bram@vim.org>
parents: 24097
diff changeset
2888 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
2889 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
2890 *p = cc;
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
2891 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
2892 *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
2893
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2894 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
2895 {
bcfff560e089 patch 8.2.2682: Vim9: cannot find Name.Func from "import * as Name"
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
2896 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
2897 {
bcfff560e089 patch 8.2.2682: Vim9: cannot find Name.Func from "import * as Name"
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
2898 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
2899 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
2900 }
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2901 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
2902 }
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2903
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2904 generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2905 import->imp_sid,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2906 idx,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2907 type);
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2908 }
21473
8bcd1ee2630b patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
2909 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
2910 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
2911 else
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2912 generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2913 import->imp_sid,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2914 import->imp_var_vals_idx,
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2915 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
2916 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2917 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2918
19530
48e71f948360 patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
2919 if (error)
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2920 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
2921 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2922 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2923
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2924 static int
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2925 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
2926 {
20189
63cc54100ae4 patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents: 20174
diff changeset
2927 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
2928
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2929 if (ufunc == NULL)
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2930 return FAIL;
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2931
21469
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
2932 // Need to compile any default values to get the argument types.
23735
7caffd835aa1 patch 8.2.2409: Vim9: profiling only works for one function
Bram Moolenaar <Bram@vim.org>
parents: 23729
diff changeset
2933 if (func_needs_compiling(ufunc, PROFILING(ufunc))
7caffd835aa1 patch 8.2.2409: Vim9: profiling only works for one function
Bram Moolenaar <Bram@vim.org>
parents: 23729
diff changeset
2934 && compile_def_function(ufunc, TRUE, PROFILING(ufunc), NULL)
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
2935 == FAIL)
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
2936 return FAIL;
21473
8bcd1ee2630b patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents: 21469
diff changeset
2937 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
2938 }
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
2939
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2940 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2941 * 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
2942 * "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
2943 * "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
2944 * 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
2945 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2946 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
2947 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
2948 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
2949 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
2950 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
2951 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
2952 int error)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2953 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2954 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
2955 char_u *name = NULL;
19509
17f0d6dc6a73 patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents: 19481
diff changeset
2956 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
2957 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
2958 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
2959
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2960 if (*(*arg + 1) == ':')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2961 {
19822
fc3cdc819d80 patch 8.2.0467: Vim9: some errors are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19818
diff changeset
2962 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
2963 {
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
2964 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
2965
24390
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
2966 // 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
2967 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
2968 {
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2969 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
2970 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
2971 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
2972 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
2973 default:
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
2974 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
2975 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
2976 }
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2977 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
2978 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
2979 res = OK;
19822
fc3cdc819d80 patch 8.2.0467: Vim9: some errors are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19818
diff changeset
2980 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2981 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2982 {
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
2983 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
2984
24390
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
2985 // 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
2986 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
2987 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
2988 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
2989
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2990 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
2991 {
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2992 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
2993 break;
24390
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
2994 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
2995 && 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
2996 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
2997 else
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
2998 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
2999 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
3000 break;
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3001 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
3002 {
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3003 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
3004 && 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
3005 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
3006 else
492f7b54f691 patch 8.2.2735: Vim9: function reference found with prefix, not without
Bram Moolenaar <Bram@vim.org>
parents: 24388
diff changeset
3007 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
3008 }
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3009 else
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3010 {
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3011 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
3012 vim_free(name);
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3013 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
3014 if (name == NULL)
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3015 return FAIL;
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3016 }
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3017 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
3018 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
3019 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
3020 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
3021 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
3022 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
3023 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
3024 }
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
3025 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
3026 {
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
3027 // 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
3028 // 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
3029 // 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
3030 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
3031 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3032 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3033 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3034 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3035 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3036 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
3037 int idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3038 int gen_load = FALSE;
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
3039 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
3040
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3041 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
3042 if (name == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3043 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3044
22596
107eae953b87 patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 22584
diff changeset
3045 if (arg_exists(*arg, len, &idx, &type, &gen_load_outer, cctx) == OK)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3046 {
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
3047 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
3048 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
3049 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3050 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3051 {
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
3052 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
3053
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
3054 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
3055 {
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
3056 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
3057 idx = lvar.lv_idx;
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
3058 if (lvar.lv_from_outer != 0)
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
3059 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
3060 else
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
3061 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
3062 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3063 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3064 {
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3065 // "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
3066 // 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
3067 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
3068 || 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
3069 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
3070
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
3071 // 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
3072 // 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
3073 // 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
3074 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
3075 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
3076 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3077 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3078 if (gen_load)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3079 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
3080 if (gen_load_outer > 0)
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
3081 {
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
3082 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
3083 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
3084 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3085 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3086
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3087 *arg = end;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3088
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3089 theend:
19818
c1c88b333481 patch 8.2.0465: Vim9: dead code and wrong return type
Bram Moolenaar <Bram@vim.org>
parents: 19785
diff changeset
3090 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
3091 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
3092 vim_free(name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3093 return res;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3094 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3095
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3096 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3097 * 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
3098 * "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
3099 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3100 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3101 compile_arguments(char_u **arg, cctx_T *cctx, int *argcount)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3102 {
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3103 char_u *p = *arg;
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3104 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
3105 int must_end = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3106
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
3107 for (;;)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3108 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3109 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
3110 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
3111 if (*p == ')')
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
3112 {
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
3113 *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
3114 return OK;
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
3115 }
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
3116 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
3117 {
fc3350a38389 patch 8.2.1719: Vim9: no error if comma is missing in between arguments
Bram Moolenaar <Bram@vim.org>
parents: 22326
diff changeset
3118 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
3119 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
3120 }
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
3121
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3122 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
3123 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3124 ++*argcount;
19437
5d34ae66118e patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents: 19423
diff changeset
3125
5d34ae66118e patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents: 19423
diff changeset
3126 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
3127 {
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
3128 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
3129 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
3130 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3131 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
3132 {
5d34ae66118e patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents: 19423
diff changeset
3133 ++p;
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
3134 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
3135 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
3136 }
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
3137 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
3138 must_end = TRUE;
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3139 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
3140 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
3141 }
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3142 failret:
20011
628011800942 patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
3143 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
3144 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3145 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3146
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3147 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3148 * 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
3149 * "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
3150 * "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
3151 * Instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3152 * EVAL arg1
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3153 * EVAL arg2
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3154 * BCALL / DCALL / UCALL
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3155 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3156 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
3157 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
3158 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
3159 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
3160 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
3161 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
3162 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
3163 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3164 char_u *name = *arg;
19257
5aab9c306181 patch 8.2.0187: reduntant code
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
3165 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
3166 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
3167 char_u namebuf[100];
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3168 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
3169 char_u *tofree = NULL;
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3170 int error = FCERR_NONE;
22914
54f796fb7cb2 patch 8.2.2004: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents: 22910
diff changeset
3171 ufunc_T *ufunc = NULL;
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3172 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
3173 int is_autoload;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3174
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 // 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
3176 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
3177 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3178 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
3179 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
3180
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3181 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
3182 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
3183 (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
3184 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
3185 (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
3186 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
3187 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
3188 && !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
3189 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3190 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
3191
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3192 *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
3193 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
3194 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
3195 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
3196 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
3197 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
3198 ++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
3199 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
3200 }
20332
a407e243c55c patch 8.2.0721: Vim9: leaking memory when skipping
Bram Moolenaar <Bram@vim.org>
parents: 20328
diff changeset
3201 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
3202 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3203
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
3204 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
3205 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
3206
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3207 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
3208 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
3209 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
3210 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3211 }
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3212 vim_strncpy(namebuf, *arg, varlen);
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3213 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
3214
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3215 *arg = skipwhite(*arg + varlen + 1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3216 if (compile_arguments(arg, cctx, &argcount) == FAIL)
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3217 goto theend;
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3218
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
3219 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
3220 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
3221 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3222 int idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3223
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3224 // builtin function
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3225 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
3226 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
3227 {
23816
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23806
diff changeset
3228 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
3229 {
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23806
diff changeset
3230 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
3231 goto theend;
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23806
diff changeset
3232 }
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23806
diff changeset
3233
22633
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
3234 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
3235 {
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
3236 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
3237 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
3238 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
3239
22772
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
3240 // 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
3241 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
3242 {
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
3243 // 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
3244 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
3245 idx = -1;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
3246 }
22637
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3247 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
3248 {
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3249 // 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
3250 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
3251 idx = -1;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3252 }
22633
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
3253 }
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
3254
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22631
diff changeset
3255 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
3256 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
3257 }
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
3258 else
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
3259 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
3260 goto theend;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3261 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3262
22910
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
3263 // 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
3264 // 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
3265 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
3266 && 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
3267 {
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
3268 // 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
3269 // 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
3270 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
3271 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
3272 {
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
3273 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
3274 goto theend;
f78057703df9 patch 8.2.2002: Vim9: lambda argument shadowed by function name
Bram Moolenaar <Bram@vim.org>
parents: 22906
diff changeset
3275 }
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3276 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3277
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3278 // 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
3279 // 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
3280 // 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
3281 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
3282 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
3283 && 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
3284 {
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
3285 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
3286 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
3287
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
3288 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
3289 goto theend;
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3290 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3291
22236
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
3292 // 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
3293 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
3294 {
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
3295 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
3296 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
3297 }
3d0632b260fd patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents: 22216
diff changeset
3298
20140
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20138
diff changeset
3299 // 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
3300 // 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
3301 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
3302 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
3303 else
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20138
diff changeset
3304 semsg(_(e_unknownfunc), namebuf);
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3305
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3306 theend:
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3307 vim_free(tofree);
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
3308 return res;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3309 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3310
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3311 // 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
3312 #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
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 * 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
3316 * 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
3317 * 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
3318 * 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
3319 * valid name.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3320 */
22936
00b0275ffe7f patch 8.2.2015: Vim9: literal dict #{} is not like any other language
Bram Moolenaar <Bram@vim.org>
parents: 22932
diff changeset
3321 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
3322 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
3323 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3324 char_u *p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3325
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3326 // 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
3327 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
3328 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3329
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3330 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
3331 // 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
3332 // 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
3333 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
3334 || !use_namespace
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3335 || 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
3336 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3337 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3338 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3339
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3340 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3341 * 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
3342 * 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
3343 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3344 char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3345 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
3346 {
19583
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
3347 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
3348 typval_T rettv;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3349
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3350 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
3351 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3352
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3353 // 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
3354 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
3355 p = arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3356 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3357 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3358 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3359
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3360 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3361 * 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
3362 * "*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
3363 * 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
3364 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3365 static int
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3366 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
3367 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3368 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
3369 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
3370 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
3371 int is_const;
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3372 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
3373
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3374 for (;;)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3375 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3376 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
3377 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3378 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
3379 return FAIL;
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3380 }
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
3381 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
3382 {
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
3383 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
3384 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
3385 }
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3386 if (*p == ']')
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3387 {
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3388 ++p;
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3389 break;
19830
6500dcaf8e1a patch 8.2.0471: missing change to compile_list()
Bram Moolenaar <Bram@vim.org>
parents: 19822
diff changeset
3390 }
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3391 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
3392 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3393 if (!is_const)
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3394 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
3395 ++count;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3396 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
3397 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3398 ++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
3399 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
3400 {
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
3401 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
3402 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
3403 }
bcd08812cde3 patch 8.2.1159: Vim9: no error for missing space after a comma
Bram Moolenaar <Bram@vim.org>
parents: 21210
diff changeset
3404 }
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3405 whitep = p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3406 p = skipwhite(p);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3407 }
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3408 *arg = p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3409
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3410 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
3411 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
3412 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3413
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3414 /*
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
3415 * 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
3416 * "*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
3417 * 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
3418 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3419 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3420 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
3421 {
23368
a7cbdb9294c4 patch 8.2.2227: Vim9: recognizing lambda is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 23364
diff changeset
3422 int r;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3423 typval_T rettv;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3424 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
3425 evalarg_T evalarg;
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
3426
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
3427 CLEAR_FIELD(evalarg);
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
3428 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
3429 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
3430
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3431 // 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
3432 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
3433 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
3434 {
1064b9f05b0a patch 8.2.1862: vim9: memory leak when compiling lambda fails
Bram Moolenaar <Bram@vim.org>
parents: 22614
diff changeset
3435 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
3436 return r;
22627
1064b9f05b0a patch 8.2.1862: vim9: memory leak when compiling lambda fails
Bram Moolenaar <Bram@vim.org>
parents: 22614
diff changeset
3437 }
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
3438
23318
c76240efdf02 patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents: 23310
diff changeset
3439 // "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
3440 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
3441 ++ufunc->uf_refcount;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
3442 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
3443
23318
c76240efdf02 patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents: 23310
diff changeset
3444 // Compile the function into instructions.
23735
7caffd835aa1 patch 8.2.2409: Vim9: profiling only works for one function
Bram Moolenaar <Bram@vim.org>
parents: 23729
diff changeset
3445 compile_def_function(ufunc, TRUE, PROFILING(ufunc), cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3446
24190
5f3a2d31c48d patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents: 24188
diff changeset
3447 // 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
3448 // 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
3449 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
3450 {
5f3a2d31c48d patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents: 24188
diff changeset
3451 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
3452
5f3a2d31c48d patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents: 24188
diff changeset
3453 *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
3454 + off;
5f3a2d31c48d patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents: 24188
diff changeset
3455 }
5f3a2d31c48d patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents: 24188
diff changeset
3456
21220
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21218
diff changeset
3457 clear_evalarg(&evalarg, NULL);
ad13736a1783 patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 21218
diff changeset
3458
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
3459 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
3460 {
4e4fd845553d patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents: 21691
diff changeset
3461 // 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
3462 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
3463
22324
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
3464 // 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
3465 // 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
3466 // 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
3467 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
3468 }
21353
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
3469
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
3470 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
3471 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3472 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3473
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3474 /*
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
3475 * 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
3476 * "*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
3477 * 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
3478 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3479 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
3480 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
3481 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3482 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
3483 int count = 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3484 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
3485 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
3486 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
3487 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
3488 int is_const;
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3489 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
3490
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3491 if (d == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3492 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
3493 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
3494 return FAIL;
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3495 for (;;)
19181
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 *key = NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3498
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3499 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
3500 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3501 *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
3502 goto failret;
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3503 }
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3504
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3505 if (**arg == '}')
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3506 break;
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3507
23088
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3508 if (**arg == '[')
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3509 {
22936
00b0275ffe7f patch 8.2.2015: Vim9: literal dict #{} is not like any other language
Bram Moolenaar <Bram@vim.org>
parents: 22932
diff changeset
3510 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
3511
23088
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3512 // {[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
3513 *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
3514 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
3515 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3516 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
3517 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
3518 {
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23816
diff changeset
3519 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
3520
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23816
diff changeset
3521 // 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
3522 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
3523 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
3524 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
3525 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3526 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
3527 key = isn->isn_arg.string;
23827
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23816
diff changeset
3528 else if (may_generate_2STRING(-1, cctx) == FAIL)
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23816
diff changeset
3529 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
3530 *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
3531 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
3532 {
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
3533 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
3534 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
3535 }
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
3536 ++*arg;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3537 }
23088
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3538 else
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3539 {
285cde4b8d0e patch 8.2.2090: Vim9: dict does not accept a key in quotes
Bram Moolenaar <Bram@vim.org>
parents: 23082
diff changeset
3540 // {"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
3541 // {'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
3542 // {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
3543 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
3544 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
3545 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
3546 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
3547 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
3548 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3549
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3550 // 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
3551 if (key != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3552 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3553 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
3554 if (item != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3555 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3556 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
3557 goto failret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3558 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3559 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
3560 if (item != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3561 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3562 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
3563 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
3564 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
3565 dictitem_free(item);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3566 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3567 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3568
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3569 if (**arg != ':')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3570 {
21759
25b659fa5ca5 patch 8.2.1429: Vim9: no error for missing white after : in dict
Bram Moolenaar <Bram@vim.org>
parents: 21755
diff changeset
3571 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
3572 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
3573 else
25b659fa5ca5 patch 8.2.1429: Vim9: no error for missing white after : in dict
Bram Moolenaar <Bram@vim.org>
parents: 21755
diff changeset
3574 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
3575 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3576 }
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3577 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
3578 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
3579 {
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
3580 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
3581 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
3582 }
25b659fa5ca5 patch 8.2.1429: Vim9: no error for missing white after : in dict
Bram Moolenaar <Bram@vim.org>
parents: 21755
diff changeset
3583
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3584 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
3585 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3586 *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
3587 goto failret;
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3588 }
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3589
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3590 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
3591 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3592 if (!is_const)
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
3593 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
3594 ++count;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3595
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3596 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
3597 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
3598 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3599 *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
3600 goto failret;
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3601 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3602 if (**arg == '}')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3603 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3604 if (**arg != ',')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3605 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3606 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
3607 goto failret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3608 }
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
3609 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
3610 {
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
3611 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
3612 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
3613 }
20023
c85d4e173cc9 patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents: 20019
diff changeset
3614 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
3615 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
3616 {
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
3617 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
3618 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
3619 }
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
3620 *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
3621 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3622
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3623 *arg = *arg + 1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3624
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3625 // 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
3626 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
3627 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
3628 *arg += STRLEN(*arg);
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3629
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3630 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
3631 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
3632 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
3633
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3634 failret:
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3635 if (*arg == NULL)
22508
ac8c4a8b8cba patch 8.2.1802: Vim9: crash with unterminated dict
Bram Moolenaar <Bram@vim.org>
parents: 22504
diff changeset
3636 {
19999
844c7646f61b patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents: 19993
diff changeset
3637 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
3638 *arg = (char_u *)"";
ac8c4a8b8cba patch 8.2.1802: Vim9: crash with unterminated dict
Bram Moolenaar <Bram@vim.org>
parents: 22504
diff changeset
3639 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3640 dict_unref(d);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3641 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3642 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3643
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3644 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3645 * Compile "&option".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3646 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3647 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3648 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
3649 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3650 typval_T rettv;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3651 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
3652 int ret;
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 // 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
3655 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
3656 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
3657 if (ret == OK)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3658 {
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21116
diff changeset
3659 // 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
3660 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
3661 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
3662 : 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
3663
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3664 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
3665 vim_free(name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3666 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3667 clear_tv(&rettv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3668
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3669 return ret;
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
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3672 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3673 * Compile "$VAR".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3674 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3675 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3676 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
3677 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3678 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
3679 int len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3680 int ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3681 char_u *name;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3682
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3683 ++*arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3684 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
3685 if (len == 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3686 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
3687 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
3688 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3689 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3690
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21116
diff changeset
3691 // 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
3692 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
3693 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
3694 vim_free(name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3695 return ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3696 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3697
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3698 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3699 * Compile "@r".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3700 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3701 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3702 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
3703 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3704 int ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3705
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3706 ++*arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3707 if (**arg == NUL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3708 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
3709 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
3710 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3711 }
21612
c495d3e30f4b patch 8.2.1356: Vim9: cannot get the percent register
Bram Moolenaar <Bram@vim.org>
parents: 21610
diff changeset
3712 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
3713 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3714 emsg_invreg(**arg);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3715 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3716 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3717 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
3718 ++*arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3719 return ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3720 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3721
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3722 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3723 * 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
3724 * 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
3725 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3726 static int
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3727 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
3728 {
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3729 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
3730
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3731 // 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
3732 while (p > start)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3733 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3734 --p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3735 if (*p == '-' || *p == '+')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3736 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3737 // 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
3738 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3739 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
3740 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3741 if (*p == '-')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3742 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
3743 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3744 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3745 #endif
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 varnumber_T val;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3748 int error = FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3749
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3750 // 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
3751 // here
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3752 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
3753 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3754 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
3755 clear_tv(rettv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3756 if (error)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3757 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3758 if (*p == '-')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3759 val = -val;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3760 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
3761 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
3762 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3763 }
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3764 else if (numeric_only)
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3765 {
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3766 ++p;
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3767 break;
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3768 }
22606
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
3769 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
3770 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3771 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
3772
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3773 // '!' 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
3774 clear_tv(rettv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3775 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
3776 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
3777 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3778 }
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3779 *end = p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3780 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3781 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3782
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3783 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3784 * 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
3785 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3786 static void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3787 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
3788 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3789 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
3790 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3791 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
3792 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
3793 *arg += 6;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3794 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3795 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
3796 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3797 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
3798 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
3799 *arg += 7;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3800 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3801 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
3802 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3803 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
3804 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
3805 *arg += 6;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3806 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3807 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
3808 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3809 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
3810 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
3811 *arg += 6;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3812 }
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
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
3815 exprtype_T
20305
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3816 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
3817 {
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
3818 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
3819 int i;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3820
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3821 switch (p[0])
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3822 {
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3823 case '=': if (p[1] == '=')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3824 type = EXPR_EQUAL;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3825 else if (p[1] == '~')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3826 type = EXPR_MATCH;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3827 break;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3828 case '!': if (p[1] == '=')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3829 type = EXPR_NEQUAL;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3830 else if (p[1] == '~')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3831 type = EXPR_NOMATCH;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3832 break;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3833 case '>': if (p[1] != '=')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3834 {
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3835 type = EXPR_GREATER;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3836 *len = 1;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3837 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3838 else
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3839 type = EXPR_GEQUAL;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3840 break;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3841 case '<': if (p[1] != '=')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3842 {
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3843 type = EXPR_SMALLER;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3844 *len = 1;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3845 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3846 else
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3847 type = EXPR_SEQUAL;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3848 break;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3849 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
3850 {
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3851 // "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
3852 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
3853 *len = 5;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3854 i = p[*len];
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3855 if (!isalnum(i) && i != '_')
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3856 {
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3857 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
3858 *type_is = TRUE;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3859 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3860 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3861 break;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3862 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3863 return type;
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3864 }
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3865
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
3866 /*
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3867 * 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
3868 */
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3869 static void
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3870 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
3871 {
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3872 evalarg_T evalarg;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3873
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3874 CLEAR_FIELD(evalarg);
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3875 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
3876 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
3877 }
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3878
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3879 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3880 * 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
3881 * 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
3882 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3883 static int
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3884 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
3885 {
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3886 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
3887
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3888 // 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
3889 while (p > start)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3890 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3891 --p;
22932
87b62395a4d1 patch 8.2.2013: Vim9: not skipping white space after unary minus
Bram Moolenaar <Bram@vim.org>
parents: 22926
diff changeset
3892 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
3893 --p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3894 if (*p == '-' || *p == '+')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3895 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3896 int negate = *p == '-';
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3897 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3898
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3899 // TODO: check type
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3900 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
3901 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3902 --p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3903 if (*p == '-')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3904 negate = !negate;
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 // 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
3907 if (negate)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3908 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
3909 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3910 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
3911 if (isn == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3912 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3913 }
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3914 else if (numeric_only)
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3915 {
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3916 ++p;
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3917 break;
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3918 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3919 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3920 {
22606
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
3921 int invert = *p == '!';
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
3922
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
3923 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
3924 {
22606
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
3925 if (p[-1] == '!')
336ac63fb987 patch 8.2.1851: Vim9: "!" followed by space incorrectly used
Bram Moolenaar <Bram@vim.org>
parents: 22598
diff changeset
3926 invert = !invert;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3927 --p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3928 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3929 if (generate_2BOOL(cctx, invert) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3930 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3931 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3932 }
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3933 *end = p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3934 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3935 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3936
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3937 /*
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3938 * Compile "(expression)": recursive!
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3939 * Return FAIL/OK.
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3940 */
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3941 static int
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3942 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
3943 {
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
3944 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
3945 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
3946
455ad460ff4f patch 8.2.2349: Vim9: cannot handle line break after parenthesis at line end
Bram Moolenaar <Bram@vim.org>
parents: 23586
diff changeset
3947 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
3948 return FAIL;
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3949 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
3950 {
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3951 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
3952 }
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3953 else
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3954 {
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3955 // 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
3956 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
3957 return FAIL;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3958 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
3959 }
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
3960 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
3961 return FAIL;
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3962 if (**arg == ')')
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3963 ++*arg;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3964 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
3965 {
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3966 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
3967 ret = FAIL;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3968 }
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3969 return ret;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3970 }
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3971
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
3972 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3973 * 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
3974 * 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
3975 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3976 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3977 compile_subscript(
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3978 char_u **arg,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3979 cctx_T *cctx,
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3980 char_u *start_leader,
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3981 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
3982 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
3983 {
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
3984 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
3985
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3986 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3987 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3988 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
3989
21353
fb8c8fcb7b60 patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents: 21345
diff changeset
3990 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
3991 {
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
3992 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
3993
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
3994 // 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
3995 // 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
3996 // 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
3997 if (next != NULL &&
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
3998 ((next[0] == '-' && next[1] == '>'
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
3999 && (next[2] == '{' || ASCII_ISALPHA(next[2])))
21512
81c47a694479 patch 8.2.1306: checking for first character of dict key is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 21504
diff changeset
4000 || (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
4001 {
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
4002 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
4003 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
4004 return FAIL;
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4005 *arg = next;
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4006 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
4007 }
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
4008 }
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
4009
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 23199
diff changeset
4010 // 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
4011 // 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
4012 if (**arg == '(')
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4013 {
20203
5a397db2c1ed patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
4014 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
4015 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
4016 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
4017
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4018 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
4019 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4020 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
4021
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4022 // 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
4023 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
4024
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4025 *arg = skipwhite(p + 1);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4026 if (compile_arguments(arg, cctx, &argcount) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4027 return FAIL;
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4028 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
4029 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4030 }
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4031 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
4032 {
21465
b5d4ab124782 patch 8.2.1283: Vim9: error for misplaced -> lacks argument
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
4033 char_u *pstart = p;
b5d4ab124782 patch 8.2.1283: Vim9: error for misplaced -> lacks argument
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
4034
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4035 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
4036 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4037 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
4038
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4039 // something->method()
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4040 // 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
4041 // -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
4042 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
4043 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4044
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4045 p += 2;
20949
62912ad41aff patch 8.2.1026: Vim9: cannot break the line after "->"
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
4046 *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
4047 // 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
4048 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
4049 {
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4050 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
4051 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
4052 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
4053 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
4054 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
4055 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
4056 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
4057
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4058 // 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
4059 // 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
4060 //
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4061 // 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
4062 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
4063 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
4064
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4065 // 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
4066 // 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
4067 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
4068
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4069 // 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
4070 if (**arg != '(')
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4071 {
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
4072 if (*skipwhite(*arg) == '(')
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
4073 emsg(_(e_nowhitespace));
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
4074 else
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23422
diff changeset
4075 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
4076 return FAIL;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4077 }
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4078 *arg = skipwhite(*arg + 1);
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4079 if (compile_arguments(arg, cctx, &argcount) == FAIL)
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4080 return FAIL;
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4081
24361
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4082 // 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
4083 // 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
4084 // 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
4085 // expects.
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4086 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
4087 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
4088 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
4089 {
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4090 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
4091 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
4092
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4093 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
4094 return FAIL;
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4095 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
4096 + 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
4097 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
4098 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
4099 + 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
4100 ((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
4101 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
4102 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
4103 + 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
4104 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
4105 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
4106
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4107 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
4108 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
4109 ((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
4110 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
4111 * (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
4112 ((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
4113 }
f76398d79c2e patch 8.2.2721: Vim9: cannot have a linebreak inside a lambda
Bram Moolenaar <Bram@vim.org>
parents: 24357
diff changeset
4114
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
4115 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
4116 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
4117 (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
4118 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4119 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4120 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4121 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4122 // 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
4123 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
4124 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
4125 {
21465
b5d4ab124782 patch 8.2.1283: Vim9: error for misplaced -> lacks argument
Bram Moolenaar <Bram@vim.org>
parents: 21463
diff changeset
4126 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
4127 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
4128 }
19848
36d629aa3d6e patch 8.2.0480: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19830
diff changeset
4129 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
4130 p += 2;
21650
79a8d723a3d2 patch 8.2.1375: Vim9: method name with digit not accepted
Bram Moolenaar <Bram@vim.org>
parents: 21648
diff changeset
4131 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
4132 ;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4133 if (*p != '(')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4134 {
19848
36d629aa3d6e patch 8.2.0480: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19830
diff changeset
4135 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
4136 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4137 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4138 // 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
4139 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
4140 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4141 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4142 }
21562
55aa283a0e5e patch 8.2.1331: Vim9: :echo with two lists doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21558
diff changeset
4143 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
4144 {
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4145 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
4146
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
4147 // 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
4148 // 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
4149 // 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
4150 // 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
4151 // 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
4152 // 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
4153 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
4154 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4155 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
4156
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4157 ++p;
21248
4edc60c9c0aa patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
4158 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
4159 return FAIL;
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4160 if (**arg == ':')
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4161 {
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4162 // 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
4163 generate_PUSHNR(cctx, 0);
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4164 }
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4165 else
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4166 {
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4167 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
4168 return FAIL;
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4169 if (**arg == ':')
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4170 {
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
4171 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
4172 ":", *arg);
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4173 return FAIL;
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4174 }
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
4175 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
4176 return FAIL;
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4177 *arg = skipwhite(*arg);
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4178 }
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4179 if (**arg == ':')
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4180 {
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4181 is_slice = TRUE;
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4182 ++*arg;
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4183 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
4184 {
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
4185 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
4186 ":", *arg);
23414
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4187 return FAIL;
9bd3873b13e2 patch 8.2.2250: Vim9: sublist is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23392
diff changeset
4188 }
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
4189 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
4190 return FAIL;
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4191 if (**arg == ']')
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4192 // 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
4193 generate_PUSHNR(cctx, -1);
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4194 else
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4195 {
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4196 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
4197 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
4198 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
4199 return FAIL;
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4200 *arg = skipwhite(*arg);
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4201 }
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4202 }
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
4203
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4204 if (**arg != ']')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4205 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4206 emsg(_(e_missbrac));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4207 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4208 }
19342
8ff84bc1c89b patch 8.2.0229: compare instructions not tested
Bram Moolenaar <Bram@vim.org>
parents: 19336
diff changeset
4209 *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
4210
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
4211 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
4212 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4213 }
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4214 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
4215 {
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4216 // 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
4217 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
4218 return FAIL;
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4219 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
4220
21208
09377fd59b2e patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents: 21202
diff changeset
4221 *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
4222 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
4223 {
a1b3804163ca patch 8.2.1789: Vim9: crash with invalid list constant
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
4224 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
4225 return FAIL;
22482
a1b3804163ca patch 8.2.1789: Vim9: crash with invalid list constant
Bram Moolenaar <Bram@vim.org>
parents: 22431
diff changeset
4226 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4227 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
4228 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
4229 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
4230 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
4231 if (p == *arg)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4232 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
4233 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
4234 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4235 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
4236 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
4237 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4238 *arg = p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4239 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4240 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4241 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4242 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4243
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4244 // 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
4245 // 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
4246 // 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
4247 // 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
4248
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4249 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4250 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4251
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4252 /*
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4253 * 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
4254 * "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
4255 *
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4256 * 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
4257 * 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
4258 *
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4259 * 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
4260 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4261
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4262 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4263 * number number constant
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4264 * 0zFFFFFFFF Blob constant
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4265 * "string" string constant
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4266 * '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
4267 * &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
4268 * @r register contents
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4269 * identifier variable value
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4270 * function() function call
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4271 * $VAR environment variable
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4272 * (expression) nested expression
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4273 * [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
4274 * {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
4275 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4276 * Also handle:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4277 * ! 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
4278 * - 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
4279 * + 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
4280 * 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
4281 * 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
4282 * 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
4283 * 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
4284 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4285 static int
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4286 compile_expr7(
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4287 char_u **arg,
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4288 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
4289 ppconst_T *ppconst)
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4290 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4291 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
4292 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
4293 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
4294 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
4295
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
4296 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
4297
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4298 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4299 * 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
4300 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4301 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
4302 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
4303 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4304 end_leader = *arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4305
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4306 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
4307 switch (**arg)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4308 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4309 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4310 * Number constant.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4311 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4312 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
4313 case '1':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4314 case '2':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4315 case '3':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4316 case '4':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4317 case '5':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4318 case '6':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4319 case '7':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4320 case '8':
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4321 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
4322 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
4323 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
4324 // 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
4325 // 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
4326 // '!'.
a7e0091a4669 patch 8.2.1421: Vim9: handling "+" and "-" before number differs from script
Bram Moolenaar <Bram@vim.org>
parents: 21739
diff changeset
4327 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
4328 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
4329 {
a7e0091a4669 patch 8.2.1421: Vim9: handling "+" and "-" before number differs from script
Bram Moolenaar <Bram@vim.org>
parents: 21739
diff changeset
4330 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
4331 return FAIL;
a7e0091a4669 patch 8.2.1421: Vim9: handling "+" and "-" before number differs from script
Bram Moolenaar <Bram@vim.org>
parents: 21739
diff changeset
4332 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4333 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4334
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4335 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4336 * String constant: "string".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4337 */
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21116
diff changeset
4338 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
4339 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4340 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4341
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4342 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4343 * 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
4344 */
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 21116
diff changeset
4345 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
4346 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4347 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4348
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4349 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4350 * Constant Vim variable.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4351 */
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4352 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
4353 ret = NOTDONE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4354 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4355
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4356 /*
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4357 * "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
4358 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4359 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
4360 && !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
4361 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4362 *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
4363 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
4364 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
4365 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4366 else
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4367 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
4368 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4369
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4370 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4371 * "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
4372 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4373 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
4374 && !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
4375 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4376 *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
4377 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
4378 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
4379 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4380 else
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4381 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
4382 break;
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4383
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4384 /*
23497
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4385 * "null" constant
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4386 */
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4387 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
4388 && !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
4389 {
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4390 *arg += 4;
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4391 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
4392 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
4393 }
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4394 else
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4395 ret = NOTDONE;
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4396 break;
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4397
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
4398 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4399 * List: [expr, expr]
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4400 */
23806
c0f2c6c56147 patch 8.2.2444: Vim9: compile error with combination of operator and list
Bram Moolenaar <Bram@vim.org>
parents: 23735
diff changeset
4401 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
4402 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
4403 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
4404 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4405
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4406 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4407 * 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
4408 */
23806
c0f2c6c56147 patch 8.2.2444: Vim9: compile error with combination of operator and list
Bram Moolenaar <Bram@vim.org>
parents: 23735
diff changeset
4409 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
4410 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
4411 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
4412 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4413
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4414 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4415 * Option value: &name
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4416 */
21903
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4417 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
4418 return FAIL;
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4419 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
4420 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4421
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4422 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4423 * Environment variable: $VAR.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4424 */
21903
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4425 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
4426 return FAIL;
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4427 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
4428 break;
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4431 * Register contents: @r.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4432 */
21903
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4433 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
4434 return FAIL;
1fc2ffadf412 patch 8.2.1501: Vim9: concatenating to constant reverses order
Bram Moolenaar <Bram@vim.org>
parents: 21901
diff changeset
4435 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
4436 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4437 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4438 * 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
4439 * 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
4440 * 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
4441 */
23368
a7cbdb9294c4 patch 8.2.2227: Vim9: recognizing lambda is too complicated
Bram Moolenaar <Bram@vim.org>
parents: 23364
diff changeset
4442 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
4443 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
4444 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
4445 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
4446 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4447
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4448 default: ret = NOTDONE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4449 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4450 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4451 if (ret == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4452 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4453
20336
2fd980fb9ab3 patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents: 20334
diff changeset
4454 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
4455 {
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
4456 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
4457 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
4458 else
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4459 // 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
4460 // 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
4461 ++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
4462 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4463 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
4464 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4465 char_u *p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4466 int r;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4467
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4468 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
4469 {
24158
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
4470 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
4471 {
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
4472 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
4473 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
4474 else
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
4475 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
4476 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4477 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4478 }
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 // "name" or "name()"
19583
ba35daca6553 patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
4481 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
4482 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
4483 {
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
4484 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
4485 return FAIL;
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
4486 }
96e0b898d5b4 patch 8.2.2744: Vim9: no way to explicitly ignore an argument
Bram Moolenaar <Bram@vim.org>
parents: 24406
diff changeset
4487
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4488 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
4489 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4490 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
4491 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4492 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
4493 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4494 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
4495 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
4496 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
4497 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4498 if (r == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4499 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4500 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4501
20322
a3e78893a90b patch 8.2.0716: Vim9: another memory leak
Bram Moolenaar <Bram@vim.org>
parents: 20320
diff changeset
4502 // Handle following "[]", ".member", etc.
a3e78893a90b patch 8.2.0716: Vim9: another memory leak
Bram Moolenaar <Bram@vim.org>
parents: 20320
diff changeset
4503 // 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
4504 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
4505 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
4506 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
4507 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
4508 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4509 // 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
4510 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
4511 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
4512 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
4513 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
4514 }
21739
caf0286cf02b patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents: 21717
diff changeset
4515 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
4516 return FAIL;
20322
a3e78893a90b patch 8.2.0716: Vim9: another memory leak
Bram Moolenaar <Bram@vim.org>
parents: 20320
diff changeset
4517 return OK;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4518 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4519
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4520 /*
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4521 * 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
4522 */
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4523 void
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4524 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
4525 {
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4526 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
4527
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4528 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
4529 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
4530 }
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4531
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4532 /*
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4533 * <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
4534 */
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4535 static int
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4536 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
4537 {
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4538 type_T *want_type = NULL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4539
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4540 // Recognize <type>
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4541 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
4542 {
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4543 ++*arg;
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
4544 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
4545 if (want_type == NULL)
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4546 return FAIL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4547
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4548 if (**arg != '>')
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4549 {
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4550 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
4551 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
4552 else
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
4553 emsg(_(e_missing_gt));
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4554 return FAIL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4555 }
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4556 ++*arg;
23491
ac5ead954dcd patch 8.2.2288: Vim9: line break and comment not always skipped
Bram Moolenaar <Bram@vim.org>
parents: 23477
diff changeset
4557 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
4558 return FAIL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4559 }
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4560
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4561 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
4562 return FAIL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4563
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4564 if (want_type != NULL)
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4565 {
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4566 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
4567 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
4568 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
4569
3261e28c638a patch 8.2.1455: Vim9: crash when using typecast before constant
Bram Moolenaar <Bram@vim.org>
parents: 21809
diff changeset
4570 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
4571 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
4572 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
4573 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
4574 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
4575 {
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
4576 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
4577 return FAIL;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4578 }
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4579 }
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4580
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4581 return OK;
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4582 }
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4583
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4584 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4585 * * number multiplication
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4586 * / number division
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4587 * % number modulo
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4588 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4589 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
4590 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
4591 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4592 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
4593 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
4594 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
4595
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4596 // get the first expression
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4597 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
4598 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4599
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4600 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4601 * 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
4602 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4603 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4604 {
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4605 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
4606 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
4607 break;
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4608 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
4609 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4610 *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
4611 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
4612 }
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4613
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4614 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
4615 {
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4616 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
4617 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4618 }
23106
b0c88aa0175b patch 8.2.2099: Vim9: some checks are not tested
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
4619 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
4620 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4621
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4622 // get the second expression
21717
ef3b31d510d2 patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents: 21715
diff changeset
4623 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
4624 return FAIL;
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4625
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4626 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
4627 && 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
4628 && 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
4629 {
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23669
diff changeset
4630 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
4631 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
4632 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
4633 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
4634
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4635 // 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
4636 switch (*op)
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4637 {
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4638 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
4639 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
4640 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
4641 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
4642 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
4643 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
4644 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
4645 break;
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4646 }
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23669
diff changeset
4647 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
4648 return FAIL;
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4649 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
4650 --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
4651 }
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4652 else
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4653 {
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4654 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
4655 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
4656 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4657 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4658
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4659 return OK;
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
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4662 /*
24085
23c692a4bc36 patch 8.2.2584: Vim9: type error for assigning "any" to a list
Bram Moolenaar <Bram@vim.org>
parents: 24067
diff changeset
4663 * + 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
4664 * - number subtraction
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4665 * .. string concatenation
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4666 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4667 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
4668 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
4669 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4670 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
4671 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
4672 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
4673 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
4674
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4675 // 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
4676 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
4677 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4678
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4679 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4680 * 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
4681 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4682 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4683 {
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4684 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
4685 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
4686 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4687 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
4688 if (next != NULL)
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4689 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4690 *arg = next_line_from_context(cctx, TRUE);
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4691 op = skipwhite(*arg);
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4692 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4693
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4694 if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(op[oplen]))
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4695 {
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4696 error_white_both(op, oplen);
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4697 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4698 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4699
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 23070
diff changeset
4700 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
4701 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4702
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4703 // 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
4704 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
4705 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
4706
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4707 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
4708 && (*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
4709 ? (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
4710 && 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
4711 : (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
4712 && 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
4713 {
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4714 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
4715 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
4716
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4717 // 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
4718 if (*op == '+')
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4719 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
4720 else if (*op == '-')
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4721 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
4722 else
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4723 {
20324
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4724 // concatenate constant strings
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4725 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
4726 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
4727 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
4728
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4729 tv1->vval.v_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
4730 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
4731 {
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4732 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
4733 return FAIL;
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4734 }
23188ef99fc2 patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20322
diff changeset
4735 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
4736 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
4737 vim_free(s1);
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4738 vim_free(s2);
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4739 }
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4740 --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
4741 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4742 else
20318
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4743 {
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4744 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
4745 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
4746 if (*op == '.')
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4747 {
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4748 if (may_generate_2STRING(-2, cctx) == FAIL
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4749 || may_generate_2STRING(-1, cctx) == FAIL)
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4750 return FAIL;
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4751 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
4752 }
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4753 else
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4754 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
4755 }
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4756 }
3cbcee39fc5c patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents: 20305
diff changeset
4757
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4758 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4759 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4760
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4761 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4762 * expr5a == expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4763 * expr5a =~ expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4764 * expr5a != expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4765 * expr5a !~ expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4766 * expr5a > expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4767 * expr5a >= expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4768 * expr5a < expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4769 * expr5a <= expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4770 * expr5a is expr5b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4771 * expr5a isnot expr5b
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 * Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4774 * 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
4775 * 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
4776 * 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
4777 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4778 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
4779 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
4780 {
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
4781 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
4782 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
4783 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
4784 int len = 2;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4785 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
4786 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
4787
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4788 // 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
4789 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
4790 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4791
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4792 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
4793 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
4794
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4795 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4796 * 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
4797 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4798 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
4799 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4800 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
4801
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4802 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
4803 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4804 *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
4805 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
4806 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4807 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
4808 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4809 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
4810 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4811 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4812 // 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
4813 if (p[len] == '?')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4814 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4815 ic = TRUE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4816 ++len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4817 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4818 // 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
4819 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
4820 ++len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4821 // 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
4822
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4823 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
4824 {
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
4825 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
4826 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4827 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4828
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4829 // 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
4830 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
4831 return FAIL;
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4832
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4833 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
4834 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4835
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4836 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
4837 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4838 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
4839 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
4840 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
4841
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4842 // 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
4843 // 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
4844 // 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
4845 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
4846 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
4847 else
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4848 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4849 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
4850 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
4851 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
4852 ? 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
4853 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
4854 --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
4855 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4856 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
4857 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4858
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4859 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
4860 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
4861 }
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 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4864 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4865
20334
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
4866 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
4867
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4868 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4869 * Compile || or &&.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4870 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4871 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
4872 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
4873 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
4874 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
4875 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
4876 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
4877 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
4878 {
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4879 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
4880 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
4881 int opchar = *op;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4882
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4883 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
4884 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4885 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
4886 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
4887
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4888 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4889 * 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
4890 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4891 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
4892 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
4893 {
24331
bd010982f0be patch 8.2.2706: Vim9: wrong line number reported for boolean operator
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
4894 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
4895 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
4896 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
4897
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4898 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
4899 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4900 *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
4901 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
4902 }
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4903
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4904 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
4905 {
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
4906 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
4907 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
4908 return FAIL;
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4909 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4910
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
4911 // 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
4912 // 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
4913 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
4914
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
4915 // 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
4916 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
4917 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
4918 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
4919 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
4920 {
24331
bd010982f0be patch 8.2.2706: Vim9: wrong line number reported for boolean operator
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
4921 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
4922 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
4923 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
4924 }
24331
bd010982f0be patch 8.2.2706: Vim9: wrong line number reported for boolean operator
Bram Moolenaar <Bram@vim.org>
parents: 24329
diff changeset
4925 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
4926
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4927 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
4928 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4929 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
4930 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4931 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4932 *(((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
4933 ++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
4934 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
4935 ? 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
4936
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4937 // 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
4938 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
4939 {
545ff3b4543c patch 8.2.2101: Vim9: memory leak when literal dict has an error
Bram Moolenaar <Bram@vim.org>
parents: 23106
diff changeset
4940 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
4941 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
4942 }
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
4943
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4944 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
4945 : 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
4946 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4947 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
4948 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4949 }
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4950
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
4951 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
4952 }
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4953 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
4954
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
4955 // 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
4956 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
4957 {
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
4958 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
4959 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
4960 }
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
4961
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4962 // 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
4963 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
4964 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4965 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4966
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4967 --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
4968 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
4969 + *(((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
4970 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
4971 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4972 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
4973 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4974
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4975 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4976 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4977
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4978 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4979 * 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
4980 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4981 * Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4982 * 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
4983 * 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
4984 * 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
4985 * 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
4986 * 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
4987 * 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
4988 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4989 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4990 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
4991 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
4992 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
4993 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
4994
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4995 // 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
4996 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
4997 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4998
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4999 // || 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
5000 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
5001 }
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5004 * 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
5005 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5006 * Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5007 * 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
5008 * 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
5009 * 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
5010 * 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
5011 * 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
5012 * 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
5013 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5014 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5015 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
5016 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
5017 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5018 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
5019
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5020 // 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
5021 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
5022 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5023
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5024 // || 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
5025 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
5026 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5027
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5028 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5029 * 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
5030 * Produces instructions:
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5031 * 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
5032 * 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
5033 * EVAL expr1a
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5034 * JUMP_ALWAYS end
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5035 * alt: EVAL expr1b
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5036 * end:
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5037 *
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5038 * Toplevel expression: expr2 ?? expr1
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5039 * Produces instructions:
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5040 * EVAL expr2 Push result of "expr2"
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5041 * 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
5042 * EVAL expr1
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5043 * end:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5044 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5045 static int
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
5046 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
5047 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5048 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
5049 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
5050 char_u *next;
20305
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
5051
21957
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
5052 // 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
5053 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
5054 {
23352
37118deff718 patch 8.2.2219: Vim9: method call with expression not supported
Bram Moolenaar <Bram@vim.org>
parents: 23346
diff changeset
5055 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
5056 return OK;
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
5057 }
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
5058
20305
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
5059 // 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
5060 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
5061 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5062
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
5063 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
5064 if (*p == '?')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5065 {
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5066 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
5067 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
5068 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
5069 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
5070 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
5071 isn_T *isn;
20966
0ee7de260208 patch 8.2.1034: compiler warning for uninitialized variables
Bram Moolenaar <Bram@vim.org>
parents: 20961
diff changeset
5072 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
5073 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
5074 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
5075 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
5076
20988
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
5077 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
5078 {
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
5079 *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
5080 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
5081 }
ae4b1d497a06 patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents: 20982
diff changeset
5082
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5083 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
5084 {
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
5085 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
5086 op_falsy ? "??" : "?", *arg);
20013
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
5087 return FAIL;
bf377a9ffccb patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents: 20011
diff changeset
5088 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5089
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5090 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
5091 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5092 // 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
5093 // 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
5094 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
5095 if (op_falsy)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5096 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
5097 else
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5098 {
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5099 int error = FALSE;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5100
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5101 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
5102 &error);
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5103 if (error)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5104 return FAIL;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5105 }
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5106 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
5107 (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
5108
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5109 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
5110 // "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
5111 generate_ppconst(cctx, ppconst);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5112 else
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5113 {
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5114 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
5115 --ppconst->pp_used;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5116 }
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5117 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5118 else
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5119 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5120 generate_ppconst(cctx, ppconst);
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5121 if (op_falsy)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5122 end_idx = instr->ga_len;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5123 generate_JUMP(cctx, op_falsy
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5124 ? 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
5125 if (op_falsy)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5126 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
5127 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5128
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5129 // 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
5130 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
5131 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
5132 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
5133 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5134
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5135 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
5136 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5137 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
5138
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5139 if (!op_falsy)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5140 {
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5141 // remember the type and drop it
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5142 --stack->ga_len;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5143 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
5144
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5145 end_idx = instr->ga_len;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5146 generate_JUMP(cctx, JUMP_ALWAYS, 0);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5147
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5148 // jump here from JUMP_IF_FALSE
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5149 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
5150 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
5151 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5152 }
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5153
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5154 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
5155 {
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5156 // Check for the ":".
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5157 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
5158 if (*p != ':')
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5159 {
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5160 emsg(_(e_missing_colon));
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5161 return FAIL;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5162 }
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5163 if (next != NULL)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5164 {
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5165 *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
5166 p = skipwhite(*arg);
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5167 }
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5168
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5169 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
5170 {
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
5171 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
5172 ":", p);
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5173 return FAIL;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5174 }
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5175
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5176 // evaluate the third expression
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5177 if (has_const_expr)
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5178 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
5179 ? 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
5180 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
5181 return FAIL;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5182 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
5183 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
5184 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5185
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5186 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
5187 {
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5188 type_T **typep;
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5189
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5190 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
5191
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5192 // 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
5193 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
5194 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
5195
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 22482
diff changeset
5196 // 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
5197 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
5198 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
5199 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5200
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5201 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
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 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
5204 }
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5205
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5206 /*
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5207 * Toplevel expression.
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5208 * 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
5209 * 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
5210 */
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5211 static int
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5212 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
5213 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5214 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
5215
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5216 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
5217 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
5218 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5219 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
5220 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
5221 }
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5222 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
5223 *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
5224 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
5225 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5226 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5227 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5228
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5229 /*
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5230 * Toplevel expression.
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5231 */
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5232 static int
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5233 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
5234 {
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5235 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
5236 }
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5237
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
5238 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5239 * compile "return [expr]"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5240 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5241 static char_u *
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
5242 compile_return(char_u *arg, int check_return_type, cctx_T *cctx)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5243 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5244 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
5245 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
5246 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
5247
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5248 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
5249 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5250 // compile return argument into instructions
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
5251 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
5252 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5253
22926
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5254 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
5255 {
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5256 stack_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
23418
681f042ae5ac patch 8.2.2252: Vim9: crash when using lambda without return type in dict
Bram Moolenaar <Bram@vim.org>
parents: 23414
diff changeset
5257 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
5258 || 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
5259 || cctx->ctx_ufunc->uf_ret_type == &t_any))
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
5260 {
22926
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5261 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
5262 }
22926
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5263 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
5264 {
22926
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5265 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
5266 && 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
5267 && 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
5268 {
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5269 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
5270 return NULL;
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5271 }
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5272 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
5273 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
5274 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
5275 }
1a393685e7ce patch 8.2.1131: Vim9: error message for returning a value is not clear
Bram Moolenaar <Bram@vim.org>
parents: 21158
diff changeset
5276 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5277 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5278 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5279 {
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
5280 // "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
5281 // 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
5282 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
5283 && 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
5284 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5285 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
5286 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5287 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5288
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5289 // 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
5290 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
5291 }
23586
8c5374ec8a3d patch 8.2.2335: Vim9: "silent return" does not restore command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 23578
diff changeset
5292
8c5374ec8a3d patch 8.2.2335: Vim9: "silent return" does not restore command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 23578
diff changeset
5293 // 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
5294 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
5295
22926
edfbb06cd0ee patch 8.2.2010: Vim9: compiling fails for unreachable return statement
Bram Moolenaar <Bram@vim.org>
parents: 22914
diff changeset
5296 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
5297 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5298
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5299 // "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
5300 return skipwhite(p);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5301 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5302
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5303 /*
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5304 * 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
5305 * 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
5306 * 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
5307 */
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5308 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
5309 exarg_getline(
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5310 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
5311 void *cookie,
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5312 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
5313 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
5314 {
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5315 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
5316 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
5317
a427f5f26419 patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents: 21881
diff changeset
5318 for (;;)
a427f5f26419 patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents: 21881
diff changeset
5319 {
22423
5b35b477eff0 patch 8.2.1760: Vim9: crash when end marker is missing
Bram Moolenaar <Bram@vim.org>
parents: 22415
diff changeset
5320 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
5321 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
5322 ++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
5323 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
5324 // 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
5325 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
5326 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
5327 }
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5328 }
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5329
24188
c20e763bc73c patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents: 24158
diff changeset
5330 void
c20e763bc73c patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents: 24158
diff changeset
5331 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
5332 {
c20e763bc73c patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents: 24158
diff changeset
5333 eap->getline = exarg_getline;
c20e763bc73c patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents: 24158
diff changeset
5334 eap->cookie = cctx;
c20e763bc73c patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents: 24158
diff changeset
5335 }
c20e763bc73c patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents: 24158
diff changeset
5336
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5337 /*
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5338 * 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
5339 */
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5340 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
5341 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
5342 {
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5343 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
5344 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
5345 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
5346 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
5347 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
5348 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
5349
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
5350 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
5351 {
f9b4576a618b patch 8.2.1657: Vim9: no proper error for nested ":def!"
Bram Moolenaar <Bram@vim.org>
parents: 22196
diff changeset
5352 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
5353 return NULL;
f9b4576a618b patch 8.2.1657: Vim9: no proper error for nested ":def!"
Bram Moolenaar <Bram@vim.org>
parents: 22196
diff changeset
5354 }
f9b4576a618b patch 8.2.1657: Vim9: no proper error for nested ":def!"
Bram Moolenaar <Bram@vim.org>
parents: 22196
diff changeset
5355
22973
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5356 if (*name_start == '/')
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5357 {
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5358 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
5359 if (*name_end == '/')
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5360 ++name_end;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5361 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
5362 }
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5363 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
5364 {
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5365 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
5366 {
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5367 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
5368 return NULL;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5369 }
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5370
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5371 // "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
5372 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
5373 return NULL;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5374 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
5375 }
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
5376
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
5377 // 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
5378 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
5379 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5380 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
5381 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
5382 }
24033
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
5383 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
5384 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
5385
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5386 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
5387 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
5388
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5389 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
5390 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
5391 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
5392 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
5393 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
5394
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20419
diff changeset
5395 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
5396 {
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
5397 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
5398 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
5399 }
24152
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5400
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5401 // 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
5402 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
5403 {
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5404 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
5405
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5406 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
5407 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
5408 {
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5409 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
5410 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
5411 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
5412 }
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5413 }
c308076e225e patch 8.2.2617: Vim9: script variable in block not found by function
Bram Moolenaar <Bram@vim.org>
parents: 24124
diff changeset
5414
23735
7caffd835aa1 patch 8.2.2409: Vim9: profiling only works for one function
Bram Moolenaar <Bram@vim.org>
parents: 23729
diff changeset
5415 if (func_needs_compiling(ufunc, PROFILING(ufunc))
7caffd835aa1 patch 8.2.2409: Vim9: profiling only works for one function
Bram Moolenaar <Bram@vim.org>
parents: 23729
diff changeset
5416 && compile_def_function(ufunc, TRUE, PROFILING(ufunc), cctx)
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
5417 == FAIL)
22369
62192fd08e0e patch 8.2.1733: Vim9: memory leaks when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
5418 {
62192fd08e0e patch 8.2.1733: Vim9: memory leaks when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
5419 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
5420 goto theend;
22369
62192fd08e0e patch 8.2.1733: Vim9: memory leaks when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 22363
diff changeset
5421 }
20279
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5422
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5423 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
5424 {
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5425 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
5426 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
5427
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5428 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
5429 r = FAIL;
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5430 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
5431 {
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
5432 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
5433 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
5434 }
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5435 }
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5436 else
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5437 {
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
5438 // 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
5439 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
5440 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
5441
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
5442 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
5443 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
5444 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
5445 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
5446 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
5447 }
20305
9a5e2370df0e patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
5448 // 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
5449
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
5450 theend:
8e1427ac2bce patch 8.2.2191: Vim9: using wrong name with lambda in nested function
Bram Moolenaar <Bram@vim.org>
parents: 23289
diff changeset
5451 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
5452 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
5453 }
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5454
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
5455 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5456 * 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
5457 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5458 int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5459 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
5460 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5461 if (*p == '=')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5462 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5463 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
5464 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5465 *heredoc = TRUE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5466 return 3;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5467 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5468 return 1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5469 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5470 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
5471 return 2;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5472 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
5473 return 3;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5474 return 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5475 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5476
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5477 // words that cannot be used as a variable
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5478 static char *reserved[] = {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5479 "true",
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5480 "false",
23497
2247a2ce3630 patch 8.2.2291: Vim9: cannot use "null" for v:null
Bram Moolenaar <Bram@vim.org>
parents: 23495
diff changeset
5481 "null",
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5482 NULL
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
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5485 /*
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5486 * 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
5487 */
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5488 static void
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5489 generate_loadvar(
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5490 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
5491 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
5492 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
5493 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
5494 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
5495 {
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5496 switch (dest)
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5497 {
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5498 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
5499 // 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
5500 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
5501 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5502 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
5503 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
5504 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
5505 else
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
5506 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
5507 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5508 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
5509 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
5510 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5511 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
5512 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
5513 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5514 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
5515 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
5516 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5517 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
5518 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
5519 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
5520 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5521 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
5522 // 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
5523 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
5524 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5525 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
5526 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
5527 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5528 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
5529 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
5530 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5531 case dest_local:
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5532 if (lvar->lv_from_outer > 0)
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
5533 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
5534 type);
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5535 else
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5536 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
5537 break;
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5538 case dest_expr:
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5539 // 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
5540 break;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5541 }
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5542 }
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5543
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5544 /*
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5545 * 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
5546 * 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
5547 */
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5548 static char_u *
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5549 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
5550 {
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5551 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
5552
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5553 if (*p == '[')
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5554 {
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5555 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
5556 (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
5557 p = skipwhite(p);
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5558 if (*p == ']')
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5559 return p + 1;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5560 return p;
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5561 }
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5562 // if (*p == '.')
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
5563 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
5564 }
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5565
20953
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5566 void
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5567 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
5568 {
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5569 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
5570
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5571 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
5572 {
20961
0e01976dfd3b patch 8.2.1032: error message for declaring a variable cannot be translated
Bram Moolenaar <Bram@vim.org>
parents: 20955
diff changeset
5573 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
5574 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
5575 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
5576 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
5577 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
5578 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
5579 return;
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
5580 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
5581 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
5582 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
5583 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
5584 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
5585 }
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
5586 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
5587 }
6b4b887a12f0 patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents: 20949
diff changeset
5588
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
5589 /*
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5590 * 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
5591 * 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
5592 * 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
5593 * 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
5594 * "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
5595 * 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
5596 */
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5597 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
5598 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
5599 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
5600 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
5601 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
5602 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
5603 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
5604 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
5605 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
5606 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5607 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
5608
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5609 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
5610 {
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5611 int cc;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5612 long numval;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5613 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
5614
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5615 *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
5616 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
5617 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5618 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
5619 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
5620 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5621 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
5622 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
5623 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
5624 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5625 // 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
5626 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
5627 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
5628 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5629 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
5630 *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
5631 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
5632 &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
5633 *p = cc;
23422
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5634 switch (opt_type)
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5635 {
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5636 case gov_unknown:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5637 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
5638 return FAIL;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5639 case gov_string:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5640 case gov_hidden_string:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5641 *type = &t_string;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5642 break;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5643 case gov_bool:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5644 case gov_hidden_bool:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5645 *type = &t_bool;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5646 break;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5647 case gov_number:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5648 case gov_hidden_number:
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5649 *type = &t_number;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5650 break;
bb0c53f4ef8b patch 8.2.2254: Vim9: bool option type is number
Bram Moolenaar <Bram@vim.org>
parents: 23418
diff changeset
5651 }
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5652 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5653 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
5654 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5655 *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
5656 *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
5657 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5658 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
5659 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5660 if (!valid_yank_reg(name[1], FALSE) || name[1] == '.')
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5661 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5662 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
5663 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
5664 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5665 *dest = dest_reg;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5666 *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
5667 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5668 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
5669 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5670 *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
5671 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5672 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
5673 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5674 *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
5675 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5676 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
5677 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5678 *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
5679 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5680 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
5681 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5682 *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
5683 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5684 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
5685 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5686 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
5687 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
5688
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5689 *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
5690 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
5691 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5692 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
5693 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
5694 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5695 // 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
5696 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
5697 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
5698 *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
5699 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
5700 *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
5701 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5702 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
5703 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5704
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5705 /*
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5706 * 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
5707 * 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
5708 */
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5709 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
5710 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
5711 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
5712 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
5713 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
5714 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
5715 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
5716 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
5717 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
5718 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
5719 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5720 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
5721 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5722 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
5723 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
5724 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
5725 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
5726 // 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
5727 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
5728 ? 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
5729 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
5730 // 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
5731 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
5732 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
5733 // 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
5734 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
5735 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
5736 // 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
5737 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
5738 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
5739 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
5740 case dest_reg:
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5741 return generate_STORE(cctx, ISN_STOREREG, name[1], NULL);
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5742 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
5743 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
5744 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
5745 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
5746 // "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
5747 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
5748 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
5749 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
5750 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
5751 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
5752 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
5753 // 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
5754 break;
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5755 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5756 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
5757 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
5758
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5759 static int
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5760 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
5761 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5762 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
5763 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
5764 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
5765 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
5766 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
5767
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5768 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
5769 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5770 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
5771 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
5772
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5773 // 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
5774 // ISN_STORENR
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5775 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
5776 && 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
5777 && 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
5778 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5779 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
5780 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
5781
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5782 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
5783 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
5784 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
5785 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
5786 --stack->ga_len;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5787 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5788 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
5789 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
5790 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
5791 else
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5792 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
5793 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5794 return OK;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5795 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5796
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
5797 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
5798 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
5799 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5800 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
5801 || 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
5802 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5803
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5804 /*
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5805 * 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
5806 * 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
5807 * 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
5808 */
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5809 static int
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5810 compile_lhs(
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5811 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
5812 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
5813 int cmdidx,
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5814 int heredoc,
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5815 int oplen,
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5816 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
5817 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5818 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
5819 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
5820
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5821 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
5822 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
5823 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
5824 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
5825
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5826 // "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
5827 // ".name".
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5828 // "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
5829 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
5830 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
5831 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
5832 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5833 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5834 // 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
5835 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
5836 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
5837 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5838
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5839 // "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
5840 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
5841 && 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
5842 --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
5843 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
5844 --var_end;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5845
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5846 // 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
5847 lhs->lhs_varlen = var_end - var_start;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5848 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
5849 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
5850 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
5851
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
5852 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
5853 // 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
5854 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
5855
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5856 if (heredoc)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5857 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
5858 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5859 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
5860
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5861 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
5862 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5863 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
5864
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5865 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
5866 &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
5867 &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
5868 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
5869 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
5870 && 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
5871 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5872 // 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
5873 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
5874 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5875 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5876 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5877 int idx;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5878
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5879 // No specific kind of variable recognized, just a name.
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5880 for (idx = 0; reserved[idx] != NULL; ++idx)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5881 if (STRCMP(reserved[idx], lhs->lhs_name) == 0)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5882 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5883 semsg(_(e_cannot_use_reserved_name), lhs->lhs_name);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5884 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5885 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5886
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5887
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5888 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
5889 &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
5890 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
5891 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5892 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5893 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
5894 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
5895 &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
5896 &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
5897 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5898 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
5899 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5900 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
5901 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5902 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5903 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
5904 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5905 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5906 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
5907 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5908 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
5909 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5910 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
5911 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5912 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5913 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5914 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5915 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5916 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
5917 && 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
5918 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
5919 ? 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
5920 cctx)
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5921 : 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
5922 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
5923 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
5924 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
5925
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5926 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
5927 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5928 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
5929 + (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
5930
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5931 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
5932 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5933 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
5934 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
5935 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
5936 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
5937 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
5938 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
5939 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5940 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5941 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
5942 == 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
5943 && script_namespace
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5944 && !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
5945 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5946 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
5947 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5948 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5949
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5950 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
5951
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5952 // 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
5953 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
5954 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
5955 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
5956 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
5957 {
23578
85ce241ff9e3 patch 8.2.2331: Vim9: wrong error when modifying dict declared with :final
Bram Moolenaar <Bram@vim.org>
parents: 23576
diff changeset
5958 // 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
5959 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
5960 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
5961 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
5962 cctx);
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5963 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
5964 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5965 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
5966 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
5967 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
5968 ((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
5969 + 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
5970 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
5971 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5972 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5973 }
24033
308d29307910 patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents: 23996
diff changeset
5974 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
5975 == FAIL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5976 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5977 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5978 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5979
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5980 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
5981 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5982 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
5983 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5984 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5985 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5986
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5987 // 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
5988 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
5989 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
5990
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5991 if (lhs->lhs_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
5992 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5993 if (is_decl && *var_end == ':')
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5994 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5995 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
5996
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
5997 // 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
5998 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
5999 {
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
6000 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
6001 return FAIL;
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 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
6004 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
6005 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
6006 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6007 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
6008 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6009 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
6010 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
6011 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6012
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
6013 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
6014 && 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
6015 && !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
6016 && 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
6017 && 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
6018 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6019 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
6020 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6021 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6022
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6023 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
6024 && 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
6025 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6026 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
6027 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6028 // +=, /=, 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
6029 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
6030 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6031 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6032 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
6033 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6034 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
6035 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6036 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6037
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
6038 // 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
6039 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
6040 || 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
6041 && 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
6042 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
6043
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
6044 // 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
6045 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
6046 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
6047 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
6048 return FAIL;
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_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
6050 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6051
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6052 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
6053 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
6054 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6055 // 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
6056 // 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
6057 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
6058 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6059 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
6060 return FAIL;
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
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6063 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
6064 || 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
6065 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6066 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
6067 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
6068
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6069 // 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
6070 // 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
6071 // "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
6072 for (;;)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6073 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6074 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
6075 if (*p != '[' && *p != '.')
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6076 break;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6077 after = p;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6078 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6079 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
6080 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6081 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
6082 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
6083 // 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
6084 // 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
6085 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
6086 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6087
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6088 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
6089 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
6090 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6091 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
6092 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6093 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6094 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6095 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
6096 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6097 }
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 return OK;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6100 }
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 /*
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6103 * 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
6104 */
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6105 static int
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6106 compile_assign_lhs(
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6107 char_u *var_start,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6108 lhs_T *lhs,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6109 int cmdidx,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6110 int is_decl,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6111 int heredoc,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6112 int oplen,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6113 cctx_T *cctx)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6114 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6115 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
6116 return FAIL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6117
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6118 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
6119 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6120 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
6121 return FAIL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6122 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6123 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
6124 && 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
6125 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6126 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
6127 return FAIL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6128 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6129 return OK;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6130 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6131
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6132 /*
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
6133 * 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
6134 * "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
6135 */
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
6136 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
6137 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
6138 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
6139 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
6140 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
6141 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
6142 {
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
6143 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
6144 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
6145 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
6146 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
6147 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
6148
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6149 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
6150 if (*p == '[')
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6151 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6152 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
6153 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
6154 {
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6155 // 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
6156 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
6157 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
6158 }
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6159 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
6160 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
6161
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6162 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
6163 {
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6164 // 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
6165 // 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
6166 *range = TRUE;
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6167 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
6168 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
6169 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
6170 || (!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
6171 {
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6172 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
6173 ":", p);
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6174 return FAIL;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6175 }
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6176 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
6177 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
6178 // 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
6179 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
6180 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
6181 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
6182 }
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6183
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6184 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
6185 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6186 // 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
6187 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
6188 r = FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6189 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6190 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6191 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
6192 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6193 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
6194 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
6195
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6196 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
6197 }
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
6198 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
6199 }
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
6200
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
6201 /*
24363
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6202 * 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
6203 */
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6204 static int
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6205 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
6206 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
6207 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
6208 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
6209 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
6210 {
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6211 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
6212 {
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6213 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
6214 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
6215 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
6216 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
6217
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6218 // 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
6219 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
6220 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
6221 {
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6222 // 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
6223 emsg(_(e_missbrac));
24379
8d5e4b50c2e1 patch 8.2.2730: Coverity complains about not restoring character
Bram Moolenaar <Bram@vim.org>
parents: 24377
diff changeset
6224 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
6225 return FAIL;
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6226 }
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6227 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
6228
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6229 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
6230 : ((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
6231 // 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
6232 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
6233 && 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
6234 && 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
6235 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
6236 return FAIL;
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6237 }
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6238 else
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6239 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
6240 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
6241 return OK;
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6242 }
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6243
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6244 /*
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
6245 * 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
6246 * 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
6247 * 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
6248 */
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
6249 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
6250 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
6251 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
6252 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
6253 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
6254 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
6255 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
6256 {
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
6257 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
6258 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
6259 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
6260
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
6261 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
6262 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
6263 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
6264 && 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
6265 {
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6266 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
6267 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
6268 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6269
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6270 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
6271 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6272 // 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
6273 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
6274 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6275 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6276 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6277 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
6278 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
6279 {
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6280 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
6281 return FAIL;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6282 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6283 if (dest_type == VAR_DICT && may_generate_2STRING(-1, cctx) == FAIL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6284 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
6285 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
6286 {
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6287 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
6288
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6289 if (range)
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6290 {
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6291 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
6292 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
6293 -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
6294 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
6295 }
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
6296 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
6297 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
6298 && 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
6299 -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
6300 return FAIL;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6301 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6302 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6303
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6304 // 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
6305 // - 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
6306 // - index
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6307 // - 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
6308 // - variable
24363
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6309 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
6310 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
6311
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
6312 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
6313 || 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
6314 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6315 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
6316 {
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
6317 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
6318 {
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6319 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
6320 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
6321 }
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6322 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
6323 {
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6324 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
6325
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
6326 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
6327 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
6328 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
6329 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6330 }
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6331 else if (range)
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6332 {
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6333 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
6334 return FAIL;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23980
diff changeset
6335 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6336 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6337 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6338 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
6339 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6340 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6341 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6342 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6343 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6344 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
6345 return FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6346 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6347
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6348 return OK;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6349 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6350
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
6351 /*
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6352 * Compile declaration and assignment:
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6353 * "let name"
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6354 * "var name = expr"
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6355 * "final name = expr"
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6356 * "const name = expr"
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6357 * "name = expr"
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6358 * "arg" points to "name".
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6359 * 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
6360 * 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
6361 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6362 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6363 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
6364 {
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6365 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
6366 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
6367 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
6368 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
6369 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
6370 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
6371 int semicolon = 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6372 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
6373 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
6374 char_u *op;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6375 int oplen = 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6376 int heredoc = FALSE;
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6377 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
6378 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
6379 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
6380 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
6381 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
6382
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6383 // 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
6384 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
6385 if (p == NULL)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6386 return *arg == '[' ? arg : NULL;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6387
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6388 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
6389 {
21421
0f0fee4122d3 patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents: 21411
diff changeset
6390 // 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
6391 // members?
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
6392 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
6393 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6394 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6395 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
6396
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6397 sp = p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6398 p = skipwhite(p);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6399 op = p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6400 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
6401
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6402 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
6403 // 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
6404 return arg;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6405
23052
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
6406 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
6407 {
21630
3c6c52fbc8ea patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents: 21614
diff changeset
6408 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
6409 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
6410 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6411
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6412 if (heredoc)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6413 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6414 list_T *l;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6415 listitem_T *li;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6416
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6417 // [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
6418 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
6419 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
6420 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
6421 if (l == NULL)
66d1131a7eff patch 8.2.1755: Vim9: crash when using invalid heredoc marker
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
6422 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6423
22343
9f5a84baa464 patch 8.2.1720: Vim9: memory leak with heredoc that isn't executed
Bram Moolenaar <Bram@vim.org>
parents: 22341
diff changeset
6424 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
6425 {
22343
9f5a84baa464 patch 8.2.1720: Vim9: memory leak with heredoc that isn't executed
Bram Moolenaar <Bram@vim.org>
parents: 22341
diff changeset
6426 // 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
6427 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
6428 {
9f5a84baa464 patch 8.2.1720: Vim9: memory leak with heredoc that isn't executed
Bram Moolenaar <Bram@vim.org>
parents: 22341
diff changeset
6429 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
6430 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
6431 }
9f5a84baa464 patch 8.2.1720: Vim9: memory leak with heredoc that isn't executed
Bram Moolenaar <Bram@vim.org>
parents: 22341
diff changeset
6432 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
6433 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6434 list_free(l);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6435 p += STRLEN(p);
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6436 end = p;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6437 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6438 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
6439 {
23052
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
6440 char_u *wp;
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
6441
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6442 // 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
6443 // 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
6444 // 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
6445
9775df18916b patch 8.2.2072: Vim9: list assign not well tested
Bram Moolenaar <Bram@vim.org>
parents: 23033
diff changeset
6446 wp = op + oplen;
23122
60a0221beab0 patch 8.2.2107: Vim9: some errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 23114
diff changeset
6447 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
6448 return FAIL;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6449 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
6450 return NULL;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6451 end = p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6452
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
6453 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
6454 {
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6455 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
6456
19942
b471038ec3ea patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19934
diff changeset
6457 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
6458 : ((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
6459 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
6460 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
6461 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
6462 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6463 }
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
6464 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
6465 FALSE, FALSE) == FAIL)
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6466 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
6467 // 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
6468 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
6469 semicolon);
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6470 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
6471 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
6472 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6473 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6474
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6475 /*
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6476 * 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
6477 * 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
6478 */
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6479 if (var_count > 0)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6480 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
6481 else
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6482 var_start = arg;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6483 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
6484 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6485 int instr_count = -1;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6486
24426
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6487 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
6488 {
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6489 // 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
6490 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
6491 {
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6492 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
6493 continue;
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6494 }
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6495 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
6496 goto theend;
78343859f42d patch 8.2.2753: Vim9: cannot ignore an item in assignment unpack
Bram Moolenaar <Bram@vim.org>
parents: 24420
diff changeset
6497 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6498 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
6499
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6500 /*
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6501 * 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
6502 */
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6503 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
6504 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
6505 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6506 if (!heredoc)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6507 {
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
6508 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
6509 {
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6510 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
6511 {
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6512 // 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
6513 p = skipwhite(op + oplen);
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6514 compile_expr0(&p, cctx);
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6515 }
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6516 }
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6517 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
6518 {
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
6519 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
6520 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
6521
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6522 // 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
6523 if (var_count == 0)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6524 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6525 int r;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6526
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6527 // for "+=", "*=", "..=" etc. first load the current value
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6528 if (*op != '=')
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6529 {
24363
1a145eb83a28 patch 8.2.2722: Vim9: crash when using LHS with double index
Bram Moolenaar <Bram@vim.org>
parents: 24361
diff changeset
6530 compile_load_lhs(&lhs, var_start, NULL, cctx);
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 if (lhs.lhs_has_index)
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6533 {
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
6534 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
6535
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
6536 // Get member from list or dict. First compile 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
6537 // index value.
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
6538 if (compile_assign_index(var_start, &lhs,
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
6539 &range, 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
6540 goto theend;
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 (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
6542 {
24452
385ccfd6b6de patch 8.2.2766: test failure
Bram Moolenaar <Bram@vim.org>
parents: 24444
diff changeset
6543 semsg(_(e_cannot_use_range_with_assignment_operator_str),
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
6544 var_start);
24456
c70dcd5ab837 patch 8.2.2768: Vim9: memory leak with blob range error
Bram Moolenaar <Bram@vim.org>
parents: 24452
diff changeset
6545 goto theend;
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 }
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
6547
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
6548 // Get the 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
6549 if (compile_member(FALSE, cctx) == FAIL)
108a6e2497f6 patch 8.2.2719: Vim9: appending to dict item doesn't work in a :def function
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
6550 goto theend;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6551 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6552 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6553
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6554 // Compile the expression. Temporarily hide the new local
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6555 // variable here, it is not available to this expression.
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6556 if (lhs.lhs_new_local)
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6557 --cctx->ctx_locals.ga_len;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6558 instr_count = instr->ga_len;
23070
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23068
diff changeset
6559 wp = op + oplen;
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23068
diff changeset
6560 if (may_get_next_line_error(wp, &p, cctx) == FAIL)
23082
2120e4b40e12 patch 8.2.2087: Vim9: memory leak when statement is truncated
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
6561 {
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6562 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
6563 ++cctx->ctx_locals.ga_len;
23070
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23068
diff changeset
6564 goto theend;
23082
2120e4b40e12 patch 8.2.2087: Vim9: memory leak when statement is truncated
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
6565 }
22631
59cd5f8b2ab2 patch 8.2.1864: Vim9: no error for wrong list type
Bram Moolenaar <Bram@vim.org>
parents: 22627
diff changeset
6566 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
6567 if (lhs.lhs_new_local)
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6568 ++cctx->ctx_locals.ga_len;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6569 if (r == FAIL)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6570 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6571 }
20871
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
6572 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
6573 {
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
6574 // For "[var; var] = expr" get the rest of the list
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
6575 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
6576 goto theend;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
6577 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6578 else
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6579 {
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6580 // 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
6581 // list.
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6582 if (generate_GETITEM(cctx, var_idx) == FAIL)
23070
6a70803f4cbe patch 8.2.2081: Vim9: cannot handle a linebreak after "=" in assignment
Bram Moolenaar <Bram@vim.org>
parents: 23068
diff changeset
6583 goto theend;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6584 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6585
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6586 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
6587 : ((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
6588 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
6589 {
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6590 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
6591 || 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
6592 && !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
6593 && 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
6594 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
6595
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6596 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
6597 {
23033
b98003d73150 patch 8.2.2063: Vim9: only one level of indexing supported
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
6598 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
6599 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
6600 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
6601 goto theend;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6602 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6603 else
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6604 {
22363
6c3d15011081 patch 8.2.1730: Vim9: cannot use member of unknown type
Bram Moolenaar <Bram@vim.org>
parents: 22343
diff changeset
6605 // 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
6606 // 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
6607 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
6608 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
6609 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
6610 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
6611 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
6612 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
6613 else
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6614 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
6615 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6616 }
21881
675bf9475fff patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
6617 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
6618 {
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6619 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
6620
24329
cd9f77409393 patch 8.2.2705: Vim9: misleading reported line number for wrong type
Bram Moolenaar <Bram@vim.org>
parents: 24295
diff changeset
6621 // 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
6622 // 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
6623 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
6624 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
6625 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
6626 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
6627 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
6628 goto theend;
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6629 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6630 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6631 else if (*p != '=' && need_type(rhs_type, lhs.lhs_member_type,
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23614
diff changeset
6632 -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
6633 goto theend;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6634 }
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6635 else if (cmdidx == CMD_final)
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6636 {
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6637 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
6638 goto theend;
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
6639 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6640 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
6641 {
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
6642 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
6643 goto theend;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6644 }
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6645 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
6646 {
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
6647 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
6648 goto theend;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6649 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6650 else
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6651 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6652 // variables are always initialized
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6653 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
6654 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
6655 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
6656 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6657 case VAR_BOOL:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6658 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
6659 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6660 case VAR_FLOAT:
19336
1cd6eab65ce0 patch 8.2.0226: compiling for loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
6661 #ifdef FEAT_FLOAT
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6662 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
6663 #endif
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6664 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6665 case VAR_STRING:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6666 generate_PUSHS(cctx, NULL);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6667 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6668 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
6669 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
6670 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6671 case VAR_FUNC:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6672 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
6673 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6674 case VAR_LIST:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6675 generate_NEWLIST(cctx, 0);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6676 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6677 case VAR_DICT:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6678 generate_NEWDICT(cctx, 0);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6679 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6680 case VAR_JOB:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6681 generate_PUSHJOB(cctx, NULL);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6682 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6683 case VAR_CHANNEL:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6684 generate_PUSHCHANNEL(cctx, NULL);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6685 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6686 case VAR_NUMBER:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6687 case VAR_UNKNOWN:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6688 case VAR_ANY:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6689 case VAR_PARTIAL:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6690 case VAR_VOID:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6691 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
6692 generate_PUSHNR(cctx, 0);
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6693 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6694 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6695 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6696 if (var_count == 0)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6697 end = p;
19336
1cd6eab65ce0 patch 8.2.0226: compiling for loop not tested
Bram Moolenaar <Bram@vim.org>
parents: 19332
diff changeset
6698 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6699
20899
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6700 // 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
6701 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
6702 break;
e76bddcf3341 patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
6703
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6704 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
6705 {
21881
675bf9475fff patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
6706 type_T *expected;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6707 type_T *stacktype;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6708
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6709 if (*op == '.')
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6710 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
6711 else
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6712 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
6713 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
6714 if (
675bf9475fff patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
6715 #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
6716 // 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
6717 !(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
6718 #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
6719 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
6720 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
6721 goto theend;
20859
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 (*op == '.')
21677
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
6724 {
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
6725 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
6726 goto theend;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
6727 }
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
6728 else if (*op == '+')
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
6729 {
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
6730 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
6731 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
6732 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
6733 goto theend;
84d38f98e5de patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents: 21650
diff changeset
6734 }
21881
675bf9475fff patch 8.2.1490: Vim9: using /= with float and number doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
6735 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
6736 goto theend;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6737 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6738
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6739 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
6740 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6741 // 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
6742 // 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
6743 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
6744 == FAIL)
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6745 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
6746 }
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6747 else
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
6748 {
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6749 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
6750 || 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
6751 || 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
6752 // ":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
6753 generate_LOCKCONST(cctx);
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
6754
23458
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
6755 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
6756 && (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
6757 || 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
6758 && 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
6759 && 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
6760 && 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
6761 // 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
6762 // 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
6763 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
6764
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
6765 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
6766 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
6767 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6768
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6769 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
6770 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
6771 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6772
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6773 // for "[var, var] = expr" drop the "expr" value
20871
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
6774 if (var_count > 0 && !semicolon)
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
6775 {
23195
75f35ae990ac patch 8.2.2143: Vim9: dead code in compiling :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23187
diff changeset
6776 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
6777 goto theend;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
6778 }
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
6779
21391
8b882afa8ed2 patch 8.2.1246: Vim9: comment after assignment doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 21387
diff changeset
6780 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
6781
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6782 theend:
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6783 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
6784 return ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6785 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6786
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6787 /*
23537
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6788 * 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
6789 * 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
6790 */
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6791 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
6792 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
6793 {
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6794 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
6795 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
6796
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6797 // 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
6798 // 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
6799 // 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
6800 // 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
6801 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
6802 ? 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
6803 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
6804 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
6805 {
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6806 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
6807 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
6808 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
6809
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6810 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
6811 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
6812 else
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6813 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
6814 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
6815 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
6816 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
6817 {
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6818 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
6819
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6820 // 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
6821 // name:
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6822 // "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
6823 // "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
6824 // "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
6825 // "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
6826 // "&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
6827 // "$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
6828 // "@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
6829 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
6830 || *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
6831 || *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
6832 || ((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
6833 || 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
6834 {
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6835 *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
6836 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
6837 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
6838 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
6839 }
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6840 }
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6841 }
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6842
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6843 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
6844 {
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6845 // [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
6846 *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
6847 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
6848 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
6849 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
6850 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
6851 }
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6852 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
6853 }
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6854
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
6855 /*
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6856 * 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
6857 */
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6858 int
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6859 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
6860 {
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6861 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
6862 {
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
6863 // "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
6864 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
6865 return OK;
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
6866 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
6867 return FAIL;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6868 }
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6869 return OK;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6870 }
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6871
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6872 /*
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6873 * Callback passed to ex_unletlock().
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6874 */
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6875 static int
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6876 compile_unlet(
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6877 lval_T *lvp,
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6878 char_u *name_end,
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6879 exarg_T *eap,
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6880 int deep UNUSED,
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6881 void *coookie)
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6882 {
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6883 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
6884 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
6885 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
6886 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
6887
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6888 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
6889 return OK;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6890
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6891 *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
6892 if (*p == '$')
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6893 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6894 // :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
6895 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
6896 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6897 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
6898 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6899 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
6900
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6901 // 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
6902 // 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
6903 // 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
6904 // 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
6905 //
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6906 // 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
6907 //
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6908 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
6909
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6910 // : 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
6911 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
6912 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6913 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
6914 ret = FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6915 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6916 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6917 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6918 // 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
6919 // 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
6920 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
6921 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6922
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6923 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
6924 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6925 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
6926 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6927 ret = FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6928 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6929 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6930 {
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6931 // 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
6932 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
6933 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6934
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23515
diff changeset
6935 *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
6936 return ret;
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6937 }
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6938
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6939 /*
24262
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
6940 * 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
6941 */
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
6942 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
6943 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
6944 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
6945 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
6946 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
6947 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
6948 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
6949 {
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
6950 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
6951 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
6952 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
6953 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
6954 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
6955 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
6956
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
6957 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
6958 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
6959
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
6960 // 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
6961 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
6962 {
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
6963 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
6964
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
6965 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
6966 {
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
6967 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
6968 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
6969 }
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
6970 }
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
6971
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
6972 // 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
6973 *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
6974 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
6975 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
6976 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
6977 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
6978 else
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
6979 {
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
6980 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
6981 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
6982 p);
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
6983 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
6984
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
6985 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
6986 *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
6987 }
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
6988 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
6989 }
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
6990
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
6991 /*
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6992 * 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
6993 * "arg" points to "var".
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6994 */
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6995 static char_u *
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
6996 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
6997 {
24262
d0e86f1b34e7 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
6998 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
6999 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
7000 cctx);
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7001 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
7002 }
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7003
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
7004 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7005 * 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
7006 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7007 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7008 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
7009 {
21146
465d6e40e79c patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
7010 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
7011 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7012
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7013 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7014 * 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
7015 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7016 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7017 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
7018 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7019 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
7020 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
7021
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7022 if (endlabel == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7023 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7024 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
7025 *el = endlabel;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7026 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
7027
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7028 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
7029 return OK;
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
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7032 static void
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
7033 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
7034 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7035 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
7036
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7037 while (*el != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7038 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7039 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
7040 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7041
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7042 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
7043 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
7044 *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
7045 vim_free(cur);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7046 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7047 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7048
19896
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7049 static void
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7050 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
7051 {
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7052 while (*el != NULL)
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7053 {
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7054 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
7055
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7056 *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
7057 vim_free(cur);
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7058 }
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7059 }
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7060
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7061 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7062 * 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
7063 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7064 static scope_T *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7065 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
7066 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7067 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
7068
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7069 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7070 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7071 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
7072 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
7073 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
7074 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
7075 return scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7076 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7077
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7078 /*
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7079 * 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
7080 */
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7081 static void
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7082 drop_scope(cctx_T *cctx)
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7083 {
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7084 scope_T *scope = cctx->ctx_scope;
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7085
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7086 if (scope == NULL)
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7087 {
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7088 iemsg("calling drop_scope() without a scope");
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7089 return;
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7090 }
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7091 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
7092 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
7093 {
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7094 case IF_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7095 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
7096 case FOR_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7097 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
7098 case WHILE_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7099 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
7100 case TRY_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7101 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
7102 case NO_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7103 case BLOCK_SCOPE:
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7104 break;
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
7105 }
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7106 vim_free(scope);
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7107 }
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7108
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7109 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7110 * compile "if expr"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7111 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7112 * "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
7113 * 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
7114 * 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
7115 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7116 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7117 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7118 * "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
7119 * 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
7120 * 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
7121 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7122 * JUMP_ALWAYS end
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7123 * else:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7124 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7125 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7126 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7127 * "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
7128 * 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
7129 * 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
7130 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7131 * JUMP_ALWAYS end
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7132 * elseif:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7133 * 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
7134 * 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
7135 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7136 * JUMP_ALWAYS end
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7137 * else:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7138 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7139 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7140 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7141 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7142 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
7143 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7144 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
7145 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
7146 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
7147 scope_T *scope;
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7148 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
7149 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
7150
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
7151 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
7152 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
7153 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
7154 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
7155 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
7156 }
23882
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7157 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
7158 {
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7159 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
7160 return NULL;
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7161 }
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7162 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
7163 clear_ppconst(&ppconst);
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7164 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
7165 {
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7166 int error = FALSE;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7167 int v;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7168
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
7169 // 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
7170 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
7171 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
7172 if (error)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7173 return NULL;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7174 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
7175 }
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7176 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
7177 {
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
7178 // 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
7179 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
7180 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
7181 return NULL;
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7182 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
7183 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
7184 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7185
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7186 // 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
7187 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
7188
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7189 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
7190 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7191 return NULL;
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7192 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
7193 // "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
7194 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
7195
20933
e2fd5f05342f patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents: 20929
diff changeset
7196 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
7197 {
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7198 // "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
7199 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
7200 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
7201 }
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7202 else
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7203 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
7204
23723
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7205 #ifdef FEAT_PROFILE
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7206 if (cctx->ctx_profiling && cctx->ctx_skip == SKIP_YES
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7207 && 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
7208 {
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7209 // 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
7210 // 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
7211 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
7212 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
7213 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
7214 }
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7215 #endif
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7216
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7217 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7218 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7219
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7220 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7221 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
7222 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7223 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
7224 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
7225 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
7226 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7227 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
7228 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
7229 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
7230
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7231 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
7232 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7233 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
7234 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7235 }
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
7236 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
7237 if (!cctx->ctx_had_return)
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7238 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
7239
23723
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7240 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
7241 {
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7242 // 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
7243 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
7244 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
7245 }
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7246 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
7247 {
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7248 // 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
7249 // 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
7250 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
7251
23723
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7252 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
7253 return p;
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7254 }
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7255
20933
e2fd5f05342f patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents: 20929
diff changeset
7256 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
7257 {
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7258 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
7259
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7260 // 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
7261 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
7262 {
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7263 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
7264 return NULL;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7265 ((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
7266 ((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
7267 --instr->ga_len;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7268 moved_cmdmod = TRUE;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7269 }
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7270
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7271 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
7272 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
7273 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
7274 // 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
7275 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
7276 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
7277 if (moved_cmdmod)
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7278 ++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
7279 }
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7280
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7281 // 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
7282 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
7283 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
7284 {
21959
67d4be2757b0 patch 8.2.1529: Vim9: :elseif may be compiled when not needed
Bram Moolenaar <Bram@vim.org>
parents: 21957
diff changeset
7285 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
7286 #ifdef FEAT_PROFILE
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7287 if (cctx->ctx_profiling)
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7288 {
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7289 // 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
7290 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
7291 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
7292 }
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7293 #endif
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7294 }
20334
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7295 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
7296 {
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7297 clear_ppconst(&ppconst);
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7298 return NULL;
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7299 }
21959
67d4be2757b0 patch 8.2.1529: Vim9: :elseif may be compiled when not needed
Bram Moolenaar <Bram@vim.org>
parents: 21957
diff changeset
7300 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
7301 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
7302 {
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7303 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
7304 return NULL;
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7305 }
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7306 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
7307 clear_ppconst(&ppconst);
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7308 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
7309 {
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7310 int error = FALSE;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7311 int v;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7312
20334
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7313 // 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
7314 // 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
7315 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
7316 if (error)
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7317 return NULL;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7318 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
7319 clear_ppconst(&ppconst);
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7320 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
7321 }
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7322 else
20334
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7323 {
b774655968b4 patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents: 20332
diff changeset
7324 // 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
7325 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
7326 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
7327 return NULL;
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7328 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
7329 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
7330
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7331 // 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
7332 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
7333
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7334 // "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
7335 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
7336 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
7337 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7338
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7339 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7340 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7341
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7342 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7343 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
7344 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7345 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
7346 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
7347 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7348 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
7349
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7350 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
7351 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7352 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
7353 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7354 }
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
7355 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
7356 if (!cctx->ctx_had_return)
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7357 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
7358 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
7359
23723
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7360 #ifdef FEAT_PROFILE
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7361 if (cctx->ctx_profiling)
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7362 {
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7363 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
7364 && ((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
7365 .isn_type == ISN_PROF_START)
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7366 // the previous block was executed, do not count "else" for profiling
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7367 --instr->ga_len;
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7368 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
7369 {
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7370 // 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
7371 // "else" for profiling
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7372 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
7373 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
7374 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
7375 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
7376 }
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7377 }
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7378 #endif
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7379
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7380 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
7381 {
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7382 // 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
7383 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
7384 {
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7385 if (!cctx->ctx_had_return
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7386 && 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
7387 JUMP_ALWAYS, cctx) == FAIL)
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7388 return NULL;
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7389 }
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7390
20933
e2fd5f05342f patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents: 20929
diff changeset
7391 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
7392 {
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7393 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
7394 {
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7395 // 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
7396 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
7397 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
7398 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
7399 }
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7400 }
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7401
20933
e2fd5f05342f patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents: 20929
diff changeset
7402 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
7403 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
7404 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7405
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7406 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7407 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7408
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7409 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7410 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
7411 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7412 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
7413 ifscope_T *ifscope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7414 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
7415 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7416
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
7417 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
7418 return NULL;
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
7419
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7420 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
7421 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7422 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
7423 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7424 }
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
7425 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
7426 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
7427 if (!cctx->ctx_had_return)
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7428 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
7429
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7430 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
7431 {
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
7432 // 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
7433 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
7434 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
7435 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7436 // 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
7437 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
7438
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7439 #ifdef FEAT_PROFILE
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7440 // 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
7441 // in is skipped
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7442 if (cctx->ctx_profiling && cctx->ctx_skip == SKIP_YES
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7443 && 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
7444 {
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7445 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
7446 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
7447 }
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
7448 #endif
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7449 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
7450
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7451 // 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
7452 // had_return flag is set.
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
7453 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
7454
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7455 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
7456 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7457 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7458
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7459 /*
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7460 * 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
7461 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7462 * Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7463 * PUSHNR -1
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7464 * 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
7465 * 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
7466 * 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
7467 * - 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
7468 * - 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
7469 * 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
7470 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7471 * 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
7472 * 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
7473 *
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7474 * 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
7475 * 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
7476 * 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
7477 * 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
7478 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7479 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
7480 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
7481 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7482 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
7483 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
7484 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
7485 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
7486 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
7487 int var_count = 0;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7488 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
7489 size_t varlen;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7490 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
7491 scope_T *scope;
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
7492 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
7493 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
7494 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
7495 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
7496 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
7497
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7498 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
7499 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
7500 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
7501 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
7502 var_count = 1;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7503
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7504 // 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
7505 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
7506 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
7507 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
7508 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
7509 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7510 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
7511 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7512 }
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
7513 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
7514 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
7515 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7516
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7517 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
7518 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7519 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7520
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7521 // 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
7522 // to -1.
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
7523 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
7524 if (loop_lvar == NULL)
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
7525 {
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
7526 // out of memory
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7527 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
7528 return NULL;
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7529 }
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
7530 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
7531
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7532 // 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
7533 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
7534 if (compile_expr0(&arg, cctx) == FAIL)
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7535 {
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7536 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
7537 return NULL;
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7538 }
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7539 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
7540
24480
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
7541 // 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
7542 // 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
7543 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
7544 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
7545 && 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
7546 {
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
7547 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
7548 vartype_name(vartype->tt_type));
19866
1136ec381dd2 patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19864
diff changeset
7549 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
7550 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7551 }
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7552
24460
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7553 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
7554 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
7555 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
7556 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
7557 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
7558 && 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
7559 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7560 if (var_count == 1)
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7561 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
7562 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
7563 && 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
7564 // 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
7565 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
7566 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7567
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7568 // CMDMOD_REV must come before the FOR instruction
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7569 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
7570
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7571 // "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
7572 scope->se_u.se_for.fs_top_label = current_instr_idx(cctx);
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
7573 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
7574
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7575 arg = arg_start;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7576 if (var_count > 1)
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7577 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7578 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
7579 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
7580
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7581 // 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
7582 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
7583 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7584 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
7585 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
7586 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7587 --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
7588 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
7589 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7590 ((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
7591 (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
7592 ++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
7593 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7594 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7595
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7596 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
7597 {
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7598 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
7599 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
7600 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
7601 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
7602 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
7603 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
7604
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7605 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
7606 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
7607 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
7608 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
7609 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
7610 if (*p == ':')
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7611 {
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7612 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
7613 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
7614 }
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7615
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7616 // 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
7617 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
7618 &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
7619 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
7620 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
7621 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7622 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
7623 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
7624 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
7625 }
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7626 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
7627 {
23171
bb7531f77529 patch 8.2.2131: Vim9: crash when lambda uses same var as assignment
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
7628 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
7629 {
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7630 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
7631 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
7632 }
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7633
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
7634 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
7635 {
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
7636 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
7637 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
7638 }
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
7639
23054
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7640 // Reserve a variable to store "var".
24460
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7641 where.wt_index = var_count > 1 ? idx + 1 : 0;
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7642 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
7643 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
7644 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
7645 else if (item_type != &t_unknown
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7646 && !(var_count > 1 && item_type == &t_any)
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7647 && 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
7648 goto failed;
f0a3adf16f01 patch 8.2.2770: Vim9: type of loop variable is not used
Bram Moolenaar <Bram@vim.org>
parents: 24456
diff changeset
7649 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
7650 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
7651 // 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
7652 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
7653
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7654 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
7655 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
7656 else
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7657 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
7658 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
7659 }
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7660
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7661 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
7662 ++p;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7663 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
7664 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
7665 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7666
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
7667 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
7668
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7669 failed:
df0548b649c1 patch 8.2.2073: Vim9: for with unpack only works for local variables
Bram Moolenaar <Bram@vim.org>
parents: 23052
diff changeset
7670 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
7671 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
7672 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7673 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7674
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7675 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7676 * compile "endfor"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7677 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7678 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7679 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
7680 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7681 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
7682 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
7683 forscope_T *forscope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7684 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7685
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
7686 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
7687 return NULL;
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7688
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7689 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
7690 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7691 emsg(_(e_for));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7692 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7693 }
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
7694 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
7695 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
7696 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
7697
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7698 // 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
7699 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
7700
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7701 // Fill in the "end" label in the FOR statement so it can jump here
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7702 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
7703 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
7704
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7705 // 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
7706 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
7707
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7708 // 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
7709 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
7710 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7711
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7712 vim_free(scope);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7713
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7714 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7715 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7716
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7717 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7718 * compile "while expr"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7719 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7720 * Produces instructions:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7721 * 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
7722 * 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
7723 * ... body ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7724 * 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
7725 * end:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7726 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7727 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7728 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7729 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
7730 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7731 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
7732 scope_T *scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7733
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7734 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
7735 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7736 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7737
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7738 // "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
7739 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
7740
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7741 // 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
7742 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
7743 return NULL;
23882
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7744 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
7745 {
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7746 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
7747 return NULL;
a4df35126d9c patch 8.2.2483: Vim9: type error for misformed expression
Bram Moolenaar <Bram@vim.org>
parents: 23877
diff changeset
7748 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7749
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7750 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
7751 return FAIL;
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
7752
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24190
diff changeset
7753 // 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
7754 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
7755
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7756 // "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
7757 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
7758 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
7759 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7760
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7761 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7762 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7763
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 * compile "endwhile"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7766 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7767 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7768 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
7769 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7770 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
7771 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
7772
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
7773 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
7774 return NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7775 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
7776 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7777 emsg(_(e_while));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7778 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7779 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7780 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
7781 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
7782
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
7783 #ifdef FEAT_PROFILE
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
7784 // 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
7785 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
7786 #endif
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
7787
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7788 // 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
7789 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
7790
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7791 // 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
7792 // 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
7793 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
7794 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
7795
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7796 vim_free(scope);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7797
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7798 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7799 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7800
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7801 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7802 * compile "continue"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7803 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7804 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7805 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
7806 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7807 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
7808 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
7809 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
7810
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7811 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7812 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7813 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7814 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7815 emsg(_(e_continue));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7816 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7817 }
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
7818 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
7819 {
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7820 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
7821 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
7822 }
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7823 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
7824 {
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7825 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
7826 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
7827 }
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23923
diff changeset
7828 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
7829 ++try_scopes;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7830 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
7831 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7832
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
7833 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
7834 // 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
7835 // "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
7836 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
7837 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
7838 // 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
7839 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
7840
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7841 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7842 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7843
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7844 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7845 * compile "break"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7846 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7847 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7848 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
7849 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7850 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
7851 endlabel_T **el;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7852
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7853 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7854 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7855 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7856 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7857 emsg(_(e_break));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7858 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7859 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7860 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
7861 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7862 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
7863 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7864
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7865 // 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
7866 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
7867 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
7868 else
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
7869 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
7870 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
7871 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7872
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7873 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7874 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7875
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7876 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7877 * 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
7878 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7879 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7880 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
7881 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7882 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
7883 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7884 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
7885 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7886
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7887 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7888 * 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
7889 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7890 static void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7891 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
7892 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7893 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
7894
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7895 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
7896 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
7897 vim_free(scope);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7898 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7899
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7900 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7901 * compile "try"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7902 * 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
7903 * finally.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7904 * 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
7905 * 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
7906 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7907 * "try"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7908 * 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
7909 * ... try block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7910 * "throw {exception}"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7911 * EVAL {exception}
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7912 * THROW create exception
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7913 * ... try block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7914 * " catch {expr}"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7915 * JUMP -> finally
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 23199
diff changeset
7916 * 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
7917 * EVAL {expr}
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7918 * MATCH
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7919 * JUMP nomatch -> catch2
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7920 * CATCH remove exception
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7921 * ... catch block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7922 * " catch"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7923 * JUMP -> finally
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7924 * 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
7925 * ... catch block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7926 * " finally"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7927 * finally:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7928 * ... finally block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7929 * " endtry"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7930 * 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
7931 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7932 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7933 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
7934 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7935 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
7936 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
7937 scope_T *scope;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7938
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
7939 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
7940 return NULL;
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
7941
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7942 // 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
7943 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
7944 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
7945 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7946
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
7947 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
7948 {
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
7949 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
7950
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
7951 // "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
7952 // 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
7953 // "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
7954 // "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
7955 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
7956 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
7957 return NULL;
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
7958 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
7959 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
7960 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
7961 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7962
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7963 // 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
7964 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
7965 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7966 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7967
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7968 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7969 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7970
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7971 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7972 * compile "catch {expr}"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7973 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7974 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7975 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
7976 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7977 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
7978 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
7979 char_u *p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7980 isn_T *isn;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7981
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
7982 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
7983 return NULL;
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
7984
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7985 // 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
7986 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
7987 compile_endblock(cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7988 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
7989
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7990 // 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
7991 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
7992 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7993 emsg(_(e_catch));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7994 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7995 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7996
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
7997 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
7998 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
7999 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
8000 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8001 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8002
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8003 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
8004 {
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8005 #ifdef FEAT_PROFILE
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8006 // the profile-start should be after the jump
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8007 if (cctx->ctx_profiling && ((isn_T *)instr->ga_data)[instr->ga_len - 1]
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8008 .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
8009 --instr->ga_len;
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8010 #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
8011 // 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
8012 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
8013 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
8014 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
8015
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8016 // 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
8017 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
8018 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
8019 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
8020 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
8021 {
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8022 // 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
8023 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
8024 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
8025 }
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8026 #ifdef FEAT_PROFILE
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8027 if (cctx->ctx_profiling)
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8028 {
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8029 // 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
8030 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
8031 // 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
8032 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
8033 }
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8034 #endif
19181
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 p = skipwhite(arg);
20059
de756b3f4dee patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents: 20055
diff changeset
8038 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
8039 {
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
8040 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
8041 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
8042 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8043 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8044 {
19316
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8045 char_u *end;
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8046 char_u *pat;
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8047 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
8048 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
8049 int len;
19316
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8050
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8051 // 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
8052 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
8053
23505
bb29b09902d5 patch 8.2.2295: incsearch does not detect empty pattern properly
Bram Moolenaar <Bram@vim.org>
parents: 23497
diff changeset
8054 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
8055 if (*end != *p)
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8056 {
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
8057 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
8058 vim_free(tofree);
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8059 return FAIL;
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8060 }
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8061 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
8062 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
8063 else
19892
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19884
diff changeset
8064 len = (int)(end - tofree);
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19884
diff changeset
8065 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
8066 vim_free(tofree);
19892
5feb426d2ea1 patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19884
diff changeset
8067 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
8068 if (pat == NULL)
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8069 return FAIL;
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8070 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
8071 return FAIL;
17dc6282f370 patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents: 19304
diff changeset
8072
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8073 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
8074 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8075
19229
d776967d0f0d patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents: 19223
diff changeset
8076 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
8077 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
8078 return NULL;
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
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8081 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
8082 return NULL;
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 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
8085 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8086 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8087 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8088
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8089 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8090 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
8091 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8092 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
8093 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
8094 isn_T *isn;
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8095 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
8096
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8097 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
8098 return NULL;
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8099
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8100 // 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
8101 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
8102 compile_endblock(cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8103 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
8104
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8105 // 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
8106 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
8107 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8108 emsg(_(e_finally));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8109 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8110 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8111
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8112 // 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
8113 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
8114 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
8115 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8116 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
8117 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8118 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8119
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8120 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
8121 #ifdef FEAT_PROFILE
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8122 if (cctx->ctx_profiling && ((isn_T *)instr->ga_data)[instr->ga_len - 1]
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8123 .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
8124 // 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
8125 --this_instr;
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8126 #endif
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8127
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8128 // 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
8129 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
8130 this_instr, cctx);
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8131
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8132 // 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
8133 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
8134 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
8135 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
8136 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
8137 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8138 // 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
8139 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
8140 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
8141 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
8142 }
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8143 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
8144 return NULL;
19181
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 // 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
8147
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8148 return arg;
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
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8151 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8152 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
8153 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8154 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
8155 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
8156 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
8157
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8158 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
8159 return NULL;
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
8160
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8161 // 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
8162 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
8163 compile_endblock(cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8164 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
8165
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8166 // 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
8167 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
8168 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8169 if (scope == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8170 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
8171 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
8172 emsg(_(e_endwhile));
19213
b18437efabac patch 8.2.0165: Coverity warning for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents: 19193
diff changeset
8173 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
8174 emsg(_(e_endfor));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8175 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8176 emsg(_(e_endif));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8177 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8178 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8179
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
8180 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
8181 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
8182 {
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8183 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
8184 && 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
8185 {
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8186 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
8187 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
8188 }
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8189
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8190 #ifdef FEAT_PROFILE
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8191 if (cctx->ctx_profiling && ((isn_T *)instr->ga_data)[instr->ga_len - 1]
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8192 .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
8193 // move the profile start after "endtry" so that it's not counted when
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8194 // the exception is rethrown.
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8195 --instr->ga_len;
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8196 #endif
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8197
23440
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8198 // 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
8199 // done by ":finally".
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8200 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
8201 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
8202
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8203 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
8204 {
b0587f7ec422 patch 8.2.2263: Vim9: compilation error with try-catch in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 23436
diff changeset
8205 // 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
8206 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
8207 + 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
8208 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
8209 }
21371
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21353
diff changeset
8210 }
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21353
diff changeset
8211
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8212 compile_endblock(cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8213
23948
9854b4c6d5e6 patch 8.2.2516: test failure on s390
Bram Moolenaar <Bram@vim.org>
parents: 23927
diff changeset
8214 if (cctx->ctx_skip != SKIP_YES)
9854b4c6d5e6 patch 8.2.2516: test failure on s390
Bram Moolenaar <Bram@vim.org>
parents: 23927
diff changeset
8215 {
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8216 // 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
8217 // instruction
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
8218 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
8219 if (cctx->ctx_skip != SKIP_YES
9854b4c6d5e6 patch 8.2.2516: test failure on s390
Bram Moolenaar <Bram@vim.org>
parents: 23927
diff changeset
8220 && generate_instr(cctx, ISN_ENDTRY) == NULL)
9854b4c6d5e6 patch 8.2.2516: test failure on s390
Bram Moolenaar <Bram@vim.org>
parents: 23927
diff changeset
8221 return NULL;
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8222 #ifdef FEAT_PROFILE
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8223 if (cctx->ctx_profiling)
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23723
diff changeset
8224 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
8225 #endif
23948
9854b4c6d5e6 patch 8.2.2516: test failure on s390
Bram Moolenaar <Bram@vim.org>
parents: 23927
diff changeset
8226 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8227 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8228 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8229
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8230 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8231 * compile "throw {expr}"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8232 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8233 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8234 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
8235 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8236 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
8237
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
8238 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
8239 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
8240 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
8241 return p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8242 if (may_generate_2STRING(-1, cctx) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8243 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8244 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
8245 return NULL;
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 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8248 }
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 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8251 * 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
8252 * 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
8253 * 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
8254 * 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
8255 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8256 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
8257 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
8258 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8259 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
8260 char_u *prev = arg;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8261 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
8262 int start_ctx_lnum = cctx->ctx_lnum;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8263
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
8264 for (;;)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8265 {
23183
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
8266 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
8267 break;
20328
445c2b2ea44b patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents: 20324
diff changeset
8268 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
8269 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8270 ++count;
21835
b530ead4265a patch 8.2.1467: Vim9: :echomsg doesn't like a dict argument
Bram Moolenaar <Bram@vim.org>
parents: 21833
diff changeset
8271 prev = p;
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
8272 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
8273 }
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
8274
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
8275 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
8276 {
24471
baf75c8e1b7b patch 8.2.2775: Vim9: wrong line number used for some commands
Bram Moolenaar <Bram@vim.org>
parents: 24460
diff changeset
8277 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
8278
baf75c8e1b7b patch 8.2.2775: Vim9: wrong line number used for some commands
Bram Moolenaar <Bram@vim.org>
parents: 24460
diff changeset
8279 // 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
8280 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
8281
23183
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
8282 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
8283 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
8284 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
8285 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
8286 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
8287 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
8288 else
4d5d12138b36 patch 8.2.2137: Vim9: :echo and :execute give error for empty argument
Bram Moolenaar <Bram@vim.org>
parents: 23171
diff changeset
8289 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
8290
baf75c8e1b7b patch 8.2.2775: Vim9: wrong line number used for some commands
Bram Moolenaar <Bram@vim.org>
parents: 24460
diff changeset
8291 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
8292 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8293 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8294 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8295
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8296 /*
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 23199
diff changeset
8297 * 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
8298 * 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
8299 * 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
8300 */
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8301 static int
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8302 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
8303 {
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8304 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
8305 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
8306
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8307 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
8308 return FAIL;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8309 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
8310 }
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8311
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8312 /*
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8313 * :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
8314 * :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
8315 */
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8316 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
8317 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
8318 {
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8319 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
8320 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
8321 char *errormsg;
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
8322 int above = eap->forceit;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
8323
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8324 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
8325
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8326 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
8327 {
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8328 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
8329
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8330 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
8331 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
8332 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
8333 }
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8334 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
8335 ++line;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8336
23156
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8337 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
8338 {
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8339 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
8340 }
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8341 else
23156
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8342 {
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8343 // 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
8344 // "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
8345 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
8346 // 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
8347 return NULL;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8348 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
8349 lnum = -1;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8350 else
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8351 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
8352 if (above)
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8353 --lnum;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23138
diff changeset
8354 }
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8355
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8356 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
8357 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
8358 }
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8359
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
8360 /*
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8361 * 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
8362 */
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8363 static char_u *
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8364 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
8365 {
20172
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
8366 char_u *p;
20174
72b437855299 patch 8.2.0642: Vim9: using invalid index
Bram Moolenaar <Bram@vim.org>
parents: 20172
diff changeset
8367 int has_expr = FALSE;
21156
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8368 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
8369
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
8370 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
8371 goto theend;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8372
20174
72b437855299 patch 8.2.0642: Vim9: using invalid index
Bram Moolenaar <Bram@vim.org>
parents: 20172
diff changeset
8373 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
8374 {
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
8375 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
8376 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
8377
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8378 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
8379
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8380 // 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
8381 // 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
8382 // 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
8383 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
8384 && *eap->arg == '!')
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8385 // :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
8386 usefilter = TRUE;
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8387 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
8388 {
21893
f19ac9b8b011 patch 8.2.1496: Vim9: cannot use " #" in a mapping
Bram Moolenaar <Bram@vim.org>
parents: 21883
diff changeset
8389 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
8390 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
8391 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
8392 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
8393 }
23477
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8394 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
8395 {
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8396 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
8397 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
8398 ++p;
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8399 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
8400 ++p;
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8401 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
8402 if (*p == '|')
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8403 {
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8404 *p = NUL;
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8405 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
8406 }
95db03521b01 patch 8.2.2281: Vim9: compiled "wincmd" cannot be followed by bar
Bram Moolenaar <Bram@vim.org>
parents: 23473
diff changeset
8407 }
21156
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8408 }
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8409
20172
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
8410 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
8411 {
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
8412 // 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
8413 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
8414 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
8415 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
8416 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
8417 }
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
8418
23344
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8419 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
8420 && STRLEN(eap->arg) > 4)
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8421 {
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8422 int delim = *eap->arg;
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8423
23505
bb29b09902d5 patch 8.2.2295: incsearch does not detect empty pattern properly
Bram Moolenaar <Bram@vim.org>
parents: 23497
diff changeset
8424 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
8425 if (*p == delim)
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8426 {
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8427 eap->arg = p + 1;
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8428 has_expr = TRUE;
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8429 }
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8430 }
1f37fd20f851 patch 8.2.2215: Vim9: not recognized in global command
Bram Moolenaar <Bram@vim.org>
parents: 23334
diff changeset
8431
23521
0ef920a03380 patch 8.2.2303: Vim9: backtick expansion doesn't work for :foldopen
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
8432 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
8433 {
0ef920a03380 patch 8.2.2303: Vim9: backtick expansion doesn't work for :foldopen
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
8434 // 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
8435 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
8436 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
8437 }
0ef920a03380 patch 8.2.2303: Vim9: backtick expansion doesn't work for :foldopen
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
8438
20172
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
8439 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
8440 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8441 int count = 0;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8442 char_u *start = skipwhite(line);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8443
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8444 // :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
8445 // PUSHS ":cmd xxx"
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8446 // eval expr1
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8447 // PUSHS "yyy"
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8448 // eval expr2
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8449 // PUSHS "zzz"
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8450 // EXECCONCAT 5
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8451 for (;;)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8452 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8453 if (p > start)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8454 {
20830
9064044fd4f6 patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
8455 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
8456 ++count;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8457 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8458 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
8459 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
8460 return NULL;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8461 may_generate_2STRING(-1, cctx);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8462 ++count;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8463 p = skipwhite(p);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8464 if (*p != '`')
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8465 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
8466 emsg(_(e_missing_backtick));
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8467 return NULL;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8468 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8469 start = p + 1;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8470
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8471 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
8472 if (p == NULL)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8473 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8474 if (*skipwhite(start) != NUL)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8475 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8476 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
8477 ++count;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8478 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8479 break;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8480 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8481 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8482 generate_EXECCONCAT(cctx, count);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8483 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8484 else
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8485 generate_EXEC(cctx, line);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8486
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8487 theend:
21156
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8488 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
8489 {
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8490 // 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
8491 --nextcmd;
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8492 *nextcmd = '|';
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8493 }
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8494
eb6c27af07dd patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents: 21146
diff changeset
8495 return nextcmd;
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8496 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8497
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8499 static void
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8500 clear_instr_ga(garray_T *gap)
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8501 {
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8502 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
8503
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8504 for (idx = 0; idx < gap->ga_len; ++idx)
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8505 delete_instr(((isn_T *)gap->ga_data) + idx);
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8506 ga_clear(gap);
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8507 }
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8508
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
8509 /*
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8510 * :s/pat/repl/
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8511 */
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8512 static char_u *
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8513 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
8514 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8515 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
8516 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
8517
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8518 if (expr != NULL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8519 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8520 int delimiter = *cmd++;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8521
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8522 // 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
8523 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
8524 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
8525 {
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8526 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
8527 char_u *end;
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8528 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
8529 int instr_count;
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8530 isn_T *instr = NULL;
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8531 isn_T *isn;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8532
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8533 cmd += 3;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8534 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
8535
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8536 // Temporarily reset the list of instructions so that the jumps
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8537 // 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
8538 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
8539 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
8540 cctx->ctx_instr.ga_data = NULL;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8541 compile_expr0(&cmd, cctx);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8542 if (end[-1] == NUL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8543 end[-1] = delimiter;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8544 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
8545 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
8546
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8547 instr_count = cctx->ctx_instr.ga_len;
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8548 instr = ALLOC_MULT(isn_T, instr_count + 1);
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8549 if (trailing_error || instr == NULL)
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8550 {
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8551 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
8552 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
8553 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
8554 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
8555 vim_free(instr);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8556 return NULL;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8557 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8558
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8559 // 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
8560 // 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
8561 // adding the ISN_SUBSTITUTE instruction.
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8562 mch_memmove(instr, cctx->ctx_instr.ga_data,
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8563 instr_count * sizeof(isn_T));
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8564 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
8565
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8566 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
8567 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
8568 {
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8569 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
8570
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8571 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
8572 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
8573 vim_free(instr);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8574 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
8575 }
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
8576 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
8577 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
8578
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8579 // skip over flags
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8580 if (*end == '&')
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8581 ++end;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8582 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
8583 ++end;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8584 return end;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8585 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8586 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8587
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8588 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
8589 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8590
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8591 static char_u *
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8592 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
8593 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8594 char_u *arg = eap->arg;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8595
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8596 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
8597 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8598 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
8599 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8600 if (cctx->ctx_redir_lhs.lhs_append)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8601 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8602 if (compile_load_lhs(&cctx->ctx_redir_lhs,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8603 cctx->ctx_redir_lhs.lhs_name, NULL, cctx) == FAIL)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8604 return NULL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8605 if (cctx->ctx_redir_lhs.lhs_has_index)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8606 emsg("redir with index not implemented yet");
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8607 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8608
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8609 // 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
8610 // in the variable.
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8611 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
8612
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8613 if (cctx->ctx_redir_lhs.lhs_append)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8614 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
8615
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8616 if (generate_store_lhs(cctx, &cctx->ctx_redir_lhs, -1) == FAIL)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8617 return NULL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8618
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8619 VIM_CLEAR(cctx->ctx_redir_lhs.lhs_name);
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8620 return arg + 3;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8621 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8622 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
8623 return NULL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8624 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8625
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8626 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
8627 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8628 int append = FALSE;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8629
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8630 // 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
8631 arg += 2;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8632 if (*arg == '>')
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8633 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8634 ++arg;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8635 append = TRUE;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8636 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8637 arg = skipwhite(arg);
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8638
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8639 if (compile_assign_lhs(arg, &cctx->ctx_redir_lhs, CMD_redir,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8640 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
8641 return NULL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8642 generate_instr(cctx, ISN_REDIRSTART);
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8643 cctx->ctx_redir_lhs.lhs_append = append;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8644
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8645 return arg + cctx->ctx_redir_lhs.lhs_varlen;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8646 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8647
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8648 // 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
8649 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
8650 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
8651
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
8652 /*
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
8653 * 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
8654 * 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
8655 */
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20419
diff changeset
8656 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
8657 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
8658 {
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
8659 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
8660
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
8661 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
8662 {
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
8663 // 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
8664 // 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
8665 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
8666 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
8667 ++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
8668 }
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
8669
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
8670 // 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
8671 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
8672 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
8673 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
8674 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
8675 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
8676 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
8677 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
8678 dfunc->df_name = vim_strsave(ufunc->uf_name);
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
8679 ++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
8680 ++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
8681 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
8682 }
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
8683
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
8684 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8685 * 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
8686 * 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
8687 * 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
8688 * 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
8689 * 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
8690 * 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
8691 * 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
8692 * "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
8693 * 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
8694 * "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
8695 * 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
8696 */
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20419
diff changeset
8697 int
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8698 compile_def_function(
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8699 ufunc_T *ufunc,
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8700 int check_return_type,
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
8701 int profiling UNUSED,
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8702 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
8703 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8704 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
8705 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
8706 char_u *p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8707 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
8708 cctx_T cctx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8709 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
8710 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
8711 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
8712 int ret = FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8713 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
8714 int save_estack_compiling = estack_compiling;
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
8715 int do_estack_push;
21463
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
8716 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
8717 #ifdef FEAT_PROFILE
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8718 int prof_lnum = -1;
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
8719 #endif
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8720
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
8721 // 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
8722 // 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
8723 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
8724 {
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
8725 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
8726 + ufunc->uf_dfunc_idx;
23360
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
8727 delete_def_function_contents(dfunc, FALSE);
20339
7587d892c00c patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20336
diff changeset
8728 }
21463
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
8729 else
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
8730 {
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
8731 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
8732 return FAIL;
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
8733 new_def_function = TRUE;
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
8734 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8735
21281
13b1567ae0c6 patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
8736 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
8737
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 20005
diff changeset
8738 CLEAR_FIELD(cctx);
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8739
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
8740 #ifdef FEAT_PROFILE
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8741 cctx.ctx_profiling = profiling;
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
8742 #endif
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8743 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
8744 cctx.ctx_lnum = -1;
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
8745 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
8746 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
8747 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
8748 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
8749 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
8750 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
8751 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
8752
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
8753 // 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
8754 // 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
8755 // 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
8756 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
8757 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
8758
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
8759 // 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
8760 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
8761 if (do_estack_push)
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
8762 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
8763 estack_compiling = TRUE;
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
8764
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
8765 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
8766 {
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
8767 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
8768 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
8769 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
8770 int i;
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
8771 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
8772 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
8773 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
8774
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
8775 // 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
8776 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
8777 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
8778 {
19946
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
8779 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
8780 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
8781 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
8782 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
8783 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
8784 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
8785 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
8786
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
8787 // 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
8788 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
8789 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
8790
26d3c1539bcc patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents: 24087
diff changeset
8791 // 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
8792 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
8793
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
8794 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
8795 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
8796
26d3c1539bcc patch 8.2.2590: Vim9: default argument value may cause internal error
Bram Moolenaar <Bram@vim.org>
parents: 24087
diff changeset
8797 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
8798 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
8799 goto erret;
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
8800
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
8801 // 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
8802 // 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
8803 // specified type.
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
8804 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
8805 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
8806 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
8807 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
8808 {
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
8809 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
8810 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
8811 }
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
8812 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
8813 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
8814 goto erret;
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
8815
8466e62a2481 patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents: 19944
diff changeset
8816 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
8817 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
8818
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24262
diff changeset
8819 // 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
8820 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
8821 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
8822 }
21469
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
8823
4d156aead799 patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents: 21467
diff changeset
8824 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
8825 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
8826 }
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
8827
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
8828 /*
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
8829 * 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
8830 */
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8831 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8832 {
21689
10866fd07595 patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents: 21683
diff changeset
8833 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
8834 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
8835 char_u *cmd;
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
8836 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
8837
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
8838 // 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
8839 // 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
8840 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
8841 goto erret;
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19904
diff changeset
8842
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8843 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
8844 // 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
8845 ++line;
20949
62912ad41aff patch 8.2.1026: Vim9: cannot break the line after "->"
Bram Moolenaar <Bram@vim.org>
parents: 20945
diff changeset
8846 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
8847 && !(*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
8848 || 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
8849 {
21455
8cc1555f2445 patch 8.2.1278: Vim9: line break after "->" only allowed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21443
diff changeset
8850 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
8851 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8852 }
24158
93e69703a290 patch 8.2.2620: Vim9: Using #{ for a dictionary gives strange errors
Bram Moolenaar <Bram@vim.org>
parents: 24154
diff changeset
8853 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
8854 goto erret;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8855 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8856 {
20955
396fe712eb0f patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents: 20953
diff changeset
8857 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
8858 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
8859 {
20055
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
8860 // beyond the last line
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
8861 #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
8862 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
8863 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
8864 #endif
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8865 break;
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8866 }
24444
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
8867 // 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
8868 // may change it.
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
8869 if (line != NULL)
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
8870 {
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
8871 line = vim_strsave(line);
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
8872 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
8873 line_to_free = line;
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
8874 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8875 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8876
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 20005
diff changeset
8877 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
8878 ea.cmdlinep = &line;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8879 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
8880
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8881 if (*ea.cmd == '#')
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8882 {
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8883 // "#" starts a comment
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8884 line = (char_u *)"";
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8885 continue;
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8886 }
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8887
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
8888 #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
8889 if (cctx.ctx_profiling && cctx.ctx_lnum != prof_lnum &&
14e92f4c98c9 patch 8.2.2403: Vim9: profiling if/elseif/endif not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
8890 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
8891 {
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8892 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
8893
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8894 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
8895 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
8896 }
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
8897 #endif
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
8898
20055
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
8899 // 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
8900 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
8901 {
20055
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
8902 case '}':
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
8903 {
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
8904 // "}" 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
8905 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
8906 ? 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
8907
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
8908 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
8909 {
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
8910 compile_endblock(&cctx);
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
8911 line = ea.cmd;
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
8912 }
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
8913 else
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
8914 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
8915 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
8916 goto erret;
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
8917 }
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
8918 if (line != NULL)
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
8919 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
8920 continue;
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
8921 }
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
8922
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
8923 case '{':
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
8924 // "{" 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
8925 // "{'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
8926 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
8927 {
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
8928 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
8929 continue;
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
8930 }
686deb5959c2 patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
8931 break;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8932 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8933
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8934 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8935 * COMMAND MODIFIERS
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8936 */
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
8937 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
8938 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
8939 == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8940 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8941 if (errormsg != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8942 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8943 // 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
8944 line = (char_u *)"";
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8945 continue;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8946 }
22699
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 22697
diff changeset
8947 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
8948 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
8949
22772
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
8950 // 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
8951 // 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
8952 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
8953 {
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
8954 if (*p == ':')
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
8955 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
8956 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
8957 break;
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
8958 }
82a7aff951d2 patch 8.2.1934: Vim9: command modifiers in :def function not tested
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
8959
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8960 // Skip ":call" to get to the function name.
21751
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21743
diff changeset
8961 p = ea.cmd;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8962 if (checkforcmd(&ea.cmd, "call", 3))
21751
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21743
diff changeset
8963 {
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21743
diff changeset
8964 if (*ea.cmd == '(')
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21743
diff changeset
8965 // not for "call()"
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21743
diff changeset
8966 ea.cmd = p;
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21743
diff changeset
8967 else
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21743
diff changeset
8968 ea.cmd = skipwhite(ea.cmd);
cc8188c22a47 patch 8.2.1425: Vim9: cannot use call() without :call
Bram Moolenaar <Bram@vim.org>
parents: 21743
diff changeset
8969 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8970
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20339
diff changeset
8971 if (!starts_with_colon)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8972 {
23537
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
8973 int assign;
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
8974
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
8975 // Check for assignment after command modifiers.
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
8976 assign = may_compile_assignment(&ea, &line, &cctx);
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
8977 if (assign == OK)
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
8978 goto nextline;
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
8979 if (assign == FAIL)
7f0fc2ab90e3 patch 8.2.2311: Vim9: cannot assign to variable that shadows command modifier
Bram Moolenaar <Bram@vim.org>
parents: 23531
diff changeset
8980 goto erret;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8981 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8982
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8983 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8984 * COMMAND after range
21335
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
8985 * 'text'->func() should not be confused with 'a mark
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8986 */
20982
bb49b5090a9c patch 8.2.1042: Vim9: cannot put an operator on the next line
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
8987 cmd = ea.cmd;
21755
3b312e56e2b8 patch 8.2.1427: Vim9: cannot use a range with marks in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21753
diff changeset
8988 if (*cmd != '\'' || starts_with_colon)
20982
bb49b5090a9c patch 8.2.1042: Vim9: cannot put an operator on the next line
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
8989 {
22260
d7c1e3efa88e patch 8.2.1679: Vim9: ":*" is not recognized as a range
Bram Moolenaar <Bram@vim.org>
parents: 22236
diff changeset
8990 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
8991 if (ea.cmd > cmd)
21335
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
8992 {
21901
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
8993 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
8994 {
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
8995 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
8996 goto erret;
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
8997 }
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
8998 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
8999 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
9000 {
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
9001 // 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
9002 // 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
9003 // 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
9004 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
9005 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
9006 goto nextline;
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
9007 }
21335
af3663df42bf patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents: 21301
diff changeset
9008 }
20982
bb49b5090a9c patch 8.2.1042: Vim9: cannot put an operator on the next line
Bram Moolenaar <Bram@vim.org>
parents: 20972
diff changeset
9009 }
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
9010 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
9011 ? 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
9012
23513
872239543313 patch 8.2.2299: Vim9: invalid memory access making error message flaky
Bram Moolenaar <Bram@vim.org>
parents: 23505
diff changeset
9013 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
9014 {
872239543313 patch 8.2.2299: Vim9: invalid memory access making error message flaky
Bram Moolenaar <Bram@vim.org>
parents: 23505
diff changeset
9015 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
9016 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
9017 goto erret;
872239543313 patch 8.2.2299: Vim9: invalid memory access making error message flaky
Bram Moolenaar <Bram@vim.org>
parents: 23505
diff changeset
9018 }
872239543313 patch 8.2.2299: Vim9: invalid memory access making error message flaky
Bram Moolenaar <Bram@vim.org>
parents: 23505
diff changeset
9019
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9020 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
9021 {
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
9022 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
9023 {
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
9024 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
9025 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
9026 }
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19229
diff changeset
9027
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9028 // 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
9029 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
9030 {
23254
4b7e996354e0 patch 8.2.2173: Vim9: get internal error when assigning to undefined variable
Bram Moolenaar <Bram@vim.org>
parents: 23245
diff changeset
9031 // 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
9032 // 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
9033 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
9034 goto erret;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9035 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9036 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9037
21957
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9038 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
9039 && 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
9040 && ea.cmdidx != CMD_else
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9041 && ea.cmdidx != CMD_endif
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9042 && ea.cmdidx != CMD_endfor
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9043 && ea.cmdidx != CMD_endwhile
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9044 && ea.cmdidx != CMD_catch
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9045 && ea.cmdidx != CMD_finally
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9046 && ea.cmdidx != CMD_endtry)
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9047 {
21957
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9048 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
9049 goto erret;
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9050 }
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9051
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9052 p = skipwhite(p);
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9053 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
9054 && 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
9055 {
22276
753452747ae5 patch 8.2.1687: Vim9: out of bounds error
Bram Moolenaar <Bram@vim.org>
parents: 22274
diff changeset
9056 if (ea.cmdidx >= 0)
753452747ae5 patch 8.2.1687: Vim9: out of bounds error
Bram Moolenaar <Bram@vim.org>
parents: 22274
diff changeset
9057 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
9058 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
9059 {
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9060 ea.forceit = TRUE;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9061 p = skipwhite(p + 1);
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9062 }
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9063 }
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9064
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9065 switch (ea.cmdidx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9066 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9067 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
9068 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
9069 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
9070 break;
49b50843e725 patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents: 20275
diff changeset
9071
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9072 case CMD_function:
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
9073 // 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
9074 // function?
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
9075 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
9076 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9077
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9078 case CMD_return:
23332
cdb706d5c43d patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents: 23330
diff changeset
9079 line = compile_return(p, check_return_type, &cctx);
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9080 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
9081 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9082
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9083 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
9084 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
9085 break;
22391
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
9086 case CMD_var:
a9fb7efa31d6 patch 8.2.1744: Vim9: using ":const!" is weird
Bram Moolenaar <Bram@vim.org>
parents: 22381
diff changeset
9087 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
9088 case CMD_const:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9089 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
9090 if (line == p)
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20842
diff changeset
9091 line = NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9092 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9093
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9094 case CMD_unlet:
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9095 case CMD_unlockvar:
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9096 case CMD_lockvar:
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9097 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
9098 break;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9099
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9100 case CMD_import:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9101 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
9102 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9103
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9104 case CMD_if:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9105 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
9106 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9107 case CMD_elseif:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9108 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
9109 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
9110 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9111 case CMD_else:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9112 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
9113 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
9114 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9115 case CMD_endif:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9116 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
9117 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9118
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9119 case CMD_while:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9120 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
9121 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9122 case CMD_endwhile:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9123 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
9124 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
9125 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9126
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9127 case CMD_for:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9128 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
9129 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9130 case CMD_endfor:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9131 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
9132 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
9133 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9134 case CMD_continue:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9135 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
9136 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9137 case CMD_break:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9138 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
9139 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9140
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9141 case CMD_try:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9142 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
9143 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9144 case CMD_catch:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9145 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
9146 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
9147 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9148 case CMD_finally:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9149 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
9150 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
9151 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9152 case CMD_endtry:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9153 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
9154 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
9155 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9156 case CMD_throw:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9157 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
9158 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9159
21196
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
9160 case CMD_eval:
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
9161 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
9162 goto erret;
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
9163
21957
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9164 // drop the result
21196
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
9165 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
9166
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
9167 line = skipwhite(p);
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
9168 break;
f45ce1ce284c patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents: 21194
diff changeset
9169
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9170 case CMD_echo:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9171 case CMD_echon:
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19521
diff changeset
9172 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
9173 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
9174 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
9175 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
9176 break;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9177
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
9178 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
9179 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
9180 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
9181 break;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22021
diff changeset
9182
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9183 case CMD_substitute:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9184 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
9185 line = (char_u *)"";
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9186 else
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9187 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9188 ea.arg = p;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9189 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
9190 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9191 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9192
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9193 case CMD_redir:
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9194 ea.arg = p;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9195 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
9196 break;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9197
21957
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9198 // 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
9199
21516
c7b2ce90c2de patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
9200 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
9201 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
9202 case CMD_insert:
23978
54b2aa1f0d42 patch 8.2.2531: Vim9: the :k command is obscure
Bram Moolenaar <Bram@vim.org>
parents: 23966
diff changeset
9203 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
9204 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
9205 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
9206 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
9207 goto erret;
c7b2ce90c2de patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents: 21512
diff changeset
9208
21210
44611891e22c patch 8.2.1156: Vim9: No error for invalid command in compiled function
Bram Moolenaar <Bram@vim.org>
parents: 21208
diff changeset
9209 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
9210 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
9211 {
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9212 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
9213 goto erret;
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9214 }
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9215 // 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
9216 line = (char_u *)"";
4343657b49fa patch 8.2.1528: Vim9: :endif not found after "if false"
Bram Moolenaar <Bram@vim.org>
parents: 21937
diff changeset
9217 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
9218
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9219 default:
21961
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
9220 if (cctx.ctx_skip == SKIP_YES)
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
9221 {
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
9222 // We don't check for a next command here.
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
9223 line = (char_u *)"";
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
9224 }
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
9225 else
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
9226 {
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
9227 // Not recognized, execute with do_cmdline_cmd().
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
9228 ea.arg = p;
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
9229 line = compile_exec(line, &ea, &cctx);
0ce86b015058 patch 8.2.1530: Vim9: test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 21959
diff changeset
9230 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9231 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9232 }
21901
1ebcce655dd3 patch 8.2.1500: Vim9: error when using address without a command
Bram Moolenaar <Bram@vim.org>
parents: 21893
diff changeset
9233 nextline:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9234 if (line == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9235 goto erret;
19894
ea4f8e789627 patch 8.2.0503: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 19892
diff changeset
9236 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
9237
22691
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22685
diff changeset
9238 // 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
9239 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
9240
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9241 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
9242 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9243 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
9244 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9245 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9246 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9247
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9248 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
9249 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9250 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
9251 emsg(_(e_endif));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9252 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
9253 emsg(_(e_endwhile));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9254 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
9255 emsg(_(e_endfor));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9256 else
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
9257 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
9258 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9259 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9260
20909
0d7465881b06 patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents: 20907
diff changeset
9261 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
9262 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9263 if (ufunc->uf_ret_type->tt_type != VAR_VOID)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9264 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21811
diff changeset
9265 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
9266 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9267 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9268
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9269 // Return zero if there is no return at the end.
23543
f90e429453fd patch 8.2.2314: Vim9: returning zero takes two instructions
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
9270 generate_instr(&cctx, ISN_RETURN_ZERO);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9271 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9272
24406
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
9273 // 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
9274 // function compiled.
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
9275 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
9276 {
8288884fdfe1 patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents: 19862
diff changeset
9277 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
9278 + 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
9279 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
9280 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
9281 #ifdef FEAT_PROFILE
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9282 if (cctx.ctx_profiling)
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9283 {
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9284 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
9285 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
9286 }
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9287 else
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
9288 #endif
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9289 {
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9290 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
9291 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
9292 }
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
9293 dfunc->df_varcount = cctx.ctx_locals_count;
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22369
diff changeset
9294 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
9295 if (cctx.ctx_outer_used)
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
9296 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
9297 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
9298 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9299
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9300 ret = OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9301
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9302 erret:
24406
a26f0fa12845 patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents: 24404
diff changeset
9303 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
9304 {
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
9305 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
9306 + 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
9307
24498
bfa495227ac6 patch 8.2.2789: Vim9: using =expr in :substitute does not handle jumps
Bram Moolenaar <Bram@vim.org>
parents: 24492
diff changeset
9308 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
9309 VIM_CLEAR(dfunc->df_name);
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9310
21463
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
9311 // 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
9312 // might as well remove it.
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
9313 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
9314 && 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
9315 {
20534
ae758aa4ee5e patch 8.2.0821: Vim9: memory leak in expr test
Bram Moolenaar <Bram@vim.org>
parents: 20532
diff changeset
9316 --def_functions.ga_len;
21463
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
9317 ufunc->uf_dfunc_idx = 0;
7f36d36f7195 patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents: 21455
diff changeset
9318 }
24404
a2a7d2d6e724 patch 8.2.2742: Vim9: when compiling a function fails it is cleared
Bram Moolenaar <Bram@vim.org>
parents: 24402
diff changeset
9319 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
9320
19896
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
9321 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
9322 drop_scope(&cctx);
92177b596695 patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents: 19894
diff changeset
9323
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9324 if (errormsg != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9325 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
9326 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
9327 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
9328 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9329
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9330 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
9331 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9332 if (ret == OK)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9333 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9334 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
9335 ret = FAIL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9336 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9337 vim_free(cctx.ctx_redir_lhs.lhs_name);
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9338 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9339
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9340 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
9341 estack_compiling = save_estack_compiling;
20538
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
9342 if (do_estack_push)
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
9343 estack_pop();
9f921ba86d05 patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents: 20534
diff changeset
9344
24444
b5fbe8280853 patch 8.2.2762: Vim9: function line truncated when compiling
Bram Moolenaar <Bram@vim.org>
parents: 24440
diff changeset
9345 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
9346 free_imported(&cctx);
20239
2135b4641680 patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20207
diff changeset
9347 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
9348 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
9349 return ret;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9350 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9351
20532
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9352 void
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9353 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
9354 {
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9355 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
9356 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
9357
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9358 // 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
9359 // argument types.
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9360 // 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
9361 // 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
9362 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
9363 {
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
9364 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
9365 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
9366 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
9367 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
9368 // 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
9369 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
9370 argcount + varargs,
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9371 &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
9372 return;
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9373 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
9374 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
9375 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
9376 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
9377 {
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9378 int i;
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9379
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9380 // 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
9381 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
9382 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
9383 }
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9384 else
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9385 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
9386 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
9387 if (varargs)
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9388 {
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9389 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
9390 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
9391 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
9392 }
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9393 }
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9394 else
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9395 // 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
9396 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
9397 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
9398 }
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9399
cb4831fa7e25 patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
9400
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9401 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9402 * 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
9403 */
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9404 void
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9405 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
9406 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9407 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
9408 {
22973
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22946
diff changeset
9409 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
9410 case ISN_EXEC:
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
9411 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
9412 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
9413 case ISN_LOADENV:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9414 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
9415 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
9416 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
9417 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
9418 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
9419 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
9420 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
9421 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
9422 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
9423 case ISN_STOREB:
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
9424 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
9425 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
9426 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
9427 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
9428 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
9429 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
9430 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9431
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9432 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
9433 {
cca0a1b4e878 patch 8.2.2786: Vim9: memory leak when using :s with expression
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
9434 int idx;
cca0a1b4e878 patch 8.2.2786: Vim9: memory leak when using :s with expression
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
9435 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
9436
cca0a1b4e878 patch 8.2.2786: Vim9: memory leak when using :s with expression
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
9437 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
9438 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
9439 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
9440 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
9441 }
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9442 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
9443
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9444 case ISN_LOADS:
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
9445 case ISN_STORES:
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
9446 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
9447 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9448
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9449 case ISN_UNLET:
20099
058b41f85bcb patch 8.2.0605: Vim9: cannot unlet an environment variable
Bram Moolenaar <Bram@vim.org>
parents: 20091
diff changeset
9450 case ISN_UNLETENV:
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9451 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
9452 break;
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
9453
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9454 case ISN_STOREOPT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9455 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
9456 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9457
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9458 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
9459 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
9460 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9461
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
9462 case ISN_PUSHJOB:
19562
6b7719b8f9b9 patch 8.2.0338: build failure without the channel feature
Bram Moolenaar <Bram@vim.org>
parents: 19558
diff changeset
9463 #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
9464 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
9465 #endif
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
9466 break;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
9467
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
9468 case ISN_PUSHCHANNEL:
19562
6b7719b8f9b9 patch 8.2.0338: build failure without the channel feature
Bram Moolenaar <Bram@vim.org>
parents: 19558
diff changeset
9469 #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
9470 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
9471 #endif
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
9472 break;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19530
diff changeset
9473
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9474 case ISN_UCALL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9475 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
9476 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9477
20283
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
9478 case ISN_FUNCREF:
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
9479 {
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
9480 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
9481 + 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
9482 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
9483
ac701146c708 patch 8.2.2190: Vim9: crash when compiled with EXITFREE
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
9484 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
9485 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
9486 }
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
9487 break;
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
9488
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
9489 case ISN_DCALL:
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
9490 {
fb69b43d73f3 patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
9491 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
9492 + 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
9493
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22369
diff changeset
9494 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
9495 && 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
9496 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
9497 }
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
9498 break;
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
9499
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
9500 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
9501 {
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
9502 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
9503 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
9504
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
9505 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
9506 {
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
9507 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
9508 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
9509 }
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
9510
30a997217524 patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents: 21562
diff changeset
9511 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
9512 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
9513 }
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
9514 break;
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21546
diff changeset
9515
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
9516 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
9517 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
9518 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
9519 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
9520
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
9521 case ISN_CMDMOD:
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
9522 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
9523 ->cmod_filter_regmatch.regprog);
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
9524 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
9525 break;
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
9526
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
9527 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
9528 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
9529 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
9530 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
9531
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
9532 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
9533 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
9534 break;
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
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 ISN_2BOOL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9537 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
9538 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
9539 case ISN_ADDBLOB:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9540 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
9541 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
9542 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
9543 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
9544 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
9545 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
9546 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
9547 case ISN_CATCH:
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
9548 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
9549 case ISN_CHECKNR:
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
9550 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
9551 case ISN_COMPAREANY:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9552 case ISN_COMPAREBLOB:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9553 case ISN_COMPAREBOOL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9554 case ISN_COMPAREDICT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9555 case ISN_COMPAREFLOAT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9556 case ISN_COMPAREFUNC:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9557 case ISN_COMPARELIST:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9558 case ISN_COMPARENR:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9559 case ISN_COMPARESPECIAL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9560 case ISN_COMPARESTRING:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9561 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
9562 case ISN_COND2BOOL:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9563 case ISN_DROP:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9564 case ISN_ECHO:
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
9565 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
9566 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
9567 case ISN_ENDTRY:
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
9568 case ISN_EXECCONCAT:
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
9569 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
9570 case ISN_FINALLY:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9571 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
9572 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
9573 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
9574 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
9575 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
9576 case ISN_LISTINDEX:
21828
af5db9b6d210 patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21826
diff changeset
9577 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
9578 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
9579 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
9580 case ISN_LOADGDICT:
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20239
diff changeset
9581 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
9582 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
9583 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
9584 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
9585 case ISN_LOADWDICT:
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22266
diff changeset
9586 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
9587 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
9588 case ISN_NEGATENR:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9589 case ISN_NEWDICT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9590 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
9591 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
9592 case ISN_OPFLOAT:
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9593 case ISN_FINISH:
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
9594 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
9595 case ISN_PCALL:
19862
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19860
diff changeset
9596 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
9597 case ISN_PROF_END:
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
9598 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
9599 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
9600 case ISN_PUSHF:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9601 case ISN_PUSHNR:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9602 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
9603 case ISN_PUT:
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9604 case ISN_REDIREND:
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9605 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
9606 case ISN_RETURN:
23543
f90e429453fd patch 8.2.2314: Vim9: returning zero takes two instructions
Bram Moolenaar <Bram@vim.org>
parents: 23537
diff changeset
9607 case ISN_RETURN_ZERO:
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
9608 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
9609 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
9610 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
9611 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
9612 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
9613 case ISN_STOREOUTER:
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
9614 case ISN_STORERANGE:
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19259
diff changeset
9615 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
9616 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
9617 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
9618 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
9619 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
9620 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
9621 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
9622 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
9623 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
9624 // nothing allocated
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9625 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9626 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9627 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9628
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9629 /*
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
9630 * 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
9631 */
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9632 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
9633 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
9634 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9635 int idx;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9636
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9637 ga_clear(&dfunc->df_def_args_isn);
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9638
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9639 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
9640 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9641 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
9642 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
9643 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
9644 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
9645 }
23729
7eef04861034 patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 23725
diff changeset
9646 #ifdef FEAT_PROFILE
7eef04861034 patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 23725
diff changeset
9647 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
9648 {
7eef04861034 patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 23725
diff changeset
9649 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
9650 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
9651 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
9652 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
9653 }
7eef04861034 patch 8.2.2406: Vim9: profiled :def function leaks memory
Bram Moolenaar <Bram@vim.org>
parents: 23725
diff changeset
9654 #endif
23360
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
9655
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
9656 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
9657 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
9658 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
9659 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
9660 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9661
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9662 /*
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
9663 * 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
9664 * 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
9665 * 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
9666 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9667 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
9668 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
9669 {
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20933
diff changeset
9670 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
9671 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9672 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
9673 + 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
9674
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
9675 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
9676 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
9677 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
9678 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
9679 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
9680 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
9681 }
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
9682 }
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
9683
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
9684 /*
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
9685 * 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
9686 */
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
9687 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
9688 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
9689 {
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
9690 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
9691 {
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
9692 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
9693 + 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
9694
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
9695 ++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
9696 }
22324
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
9697 }
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22318
diff changeset
9698
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9699 #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
9700 /*
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9701 * 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
9702 */
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9703 void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9704 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
9705 {
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9706 int idx;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9707
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9708 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
9709 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9710 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
9711
23360
eb7d8f39363c patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents: 23352
diff changeset
9712 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
9713 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
9714 }
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9715
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19623
diff changeset
9716 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
9717 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9718 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9719
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 #endif // FEAT_EVAL