Mercurial > vim
annotate src/vim9compile.c @ 21745:35921b7fc07a v8.2.1422
patch 8.2.1422: the Mac GUI implementation is outdated
Commit: https://github.com/vim/vim/commit/097148e849136b49052b1b5123c714fb1d74db9b
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Aug 11 21:58:20 2020 +0200
patch 8.2.1422: the Mac GUI implementation is outdated
Problem: The Mac GUI implementation is outdated and probably doesn't even
work.
Solution: Remove the Mac GUI code. The MacVim project provides the
supported Vim GUI version.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 11 Aug 2020 22:00:04 +0200 |
parents | a7e0091a4669 |
children | cc8188c22a47 |
rev | line source |
---|---|
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 * vim9compile.c: :def and dealing with instructions |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 #define USING_FLOAT_STUFF |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 #include "vim.h" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 #if defined(FEAT_EVAL) || defined(PROTO) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 #ifdef VMS |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 # include <float.h> |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 #endif |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 #define DEFINE_VIM9_GLOBALS |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 #include "vim9.h" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
26 // values for ctx_skip |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
27 typedef enum { |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
28 SKIP_NOT, // condition is a constant, produce code |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
29 SKIP_YES, // condition is a constant, do NOT produce code |
20933
e2fd5f05342f
patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents:
20929
diff
changeset
|
30 SKIP_UNKNOWN // condition is not a constant, produce code |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
31 } skip_T; |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
32 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 * Chain of jump instructions where the end label needs to be set. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 typedef struct endlabel_S endlabel_T; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 struct endlabel_S { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 endlabel_T *el_next; // chain end_label locations |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 int el_end_label; // instruction idx where to set end |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 }; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 * info specific for the scope of :if / elseif / else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 typedef struct { |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
46 int is_seen_else; |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
47 int is_had_return; // every block ends in :return |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 int is_if_label; // instruction idx at IF or ELSEIF |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 endlabel_T *is_end_label; // instructions to set end label |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 } ifscope_T; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 * info specific for the scope of :while |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 typedef struct { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 int ws_top_label; // instruction idx at WHILE |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 endlabel_T *ws_end_label; // instructions to set end |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 } whilescope_T; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 * info specific for the scope of :for |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 typedef struct { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 int fs_top_label; // instruction idx at FOR |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 endlabel_T *fs_end_label; // break instructions |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 } forscope_T; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 * info specific for the scope of :try |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 typedef struct { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 int ts_try_label; // instruction idx at TRY |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 endlabel_T *ts_end_label; // jump to :finally or :endtry |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 int ts_catch_label; // instruction idx of last CATCH |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 int ts_caught_all; // "catch" without argument encountered |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 } tryscope_T; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 typedef enum { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 NO_SCOPE, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 IF_SCOPE, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 WHILE_SCOPE, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 FOR_SCOPE, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 TRY_SCOPE, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 BLOCK_SCOPE |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 } scopetype_T; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 * Info for one scope, pointed to by "ctx_scope". |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 typedef struct scope_S scope_T; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 struct scope_S { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 scope_T *se_outer; // scope containing this one |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 scopetype_T se_type; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 int se_local_count; // ctx_locals.ga_len before scope |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
95 skip_T se_skip_save; // ctx_skip before the block |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 union { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 ifscope_T se_if; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 whilescope_T se_while; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
99 forscope_T se_for; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 tryscope_T se_try; |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19223
diff
changeset
|
101 } se_u; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 }; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 * Entry for "ctx_locals". Used for arguments and local variables. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 typedef struct { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 char_u *lv_name; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 type_T *lv_type; |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
110 int lv_idx; // index of the variable on the stack |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
111 int lv_from_outer; // when TRUE using ctx_outer scope |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
112 int lv_const; // when TRUE cannot be assigned to |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
113 int lv_arg; // when TRUE this is an argument |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
114 } lvar_T; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
115 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 * Context for compiling lines of Vim script. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 * Stores info about the local variables and condition stack. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 struct cctx_S { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
121 ufunc_T *ctx_ufunc; // current function |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
122 int ctx_lnum; // line number in current function |
20059
de756b3f4dee
patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents:
20055
diff
changeset
|
123 char_u *ctx_line_start; // start of current line or NULL |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
124 garray_T ctx_instr; // generated instructions |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
126 garray_T ctx_locals; // currently visible local variables |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
127 int ctx_locals_count; // total number of local variables |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
128 |
20247
e46e72aaff74
patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20244
diff
changeset
|
129 int ctx_closure_count; // number of closures created in the |
e46e72aaff74
patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20244
diff
changeset
|
130 // function |
e46e72aaff74
patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20244
diff
changeset
|
131 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
132 garray_T ctx_imports; // imported items |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 |
20907
4eeda7139133
patch 8.2.1005: Vim9: using TRUE/FALSE/MAYBE for ctx_skip is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20899
diff
changeset
|
134 skip_T ctx_skip; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
135 scope_T *ctx_scope; // current scope, NULL at toplevel |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
136 int ctx_had_return; // last seen statement was "return" |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
137 |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
138 cctx_T *ctx_outer; // outer scope for lambda or nested |
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
139 // function |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
140 int ctx_outer_used; // var in ctx_outer was used |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
141 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
142 garray_T ctx_type_stack; // type of each item on the stack |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
143 garray_T *ctx_type_list; // list of pointers to allocated types |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
144 }; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
145 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
146 static char e_var_notfound[] = N_("E1001: variable not found: %s"); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
147 static char e_syntax_at[] = N_("E1002: Syntax error at %s"); |
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
|
148 static char e_used_as_arg[] = N_("E1006: %s is used as an argument"); |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
149 static char e_cannot_use_void[] = N_("E1031: Cannot use void value"); |
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
|
150 static char e_namespace[] = N_("E1075: Namespace not supported: %s"); |
21646
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
151 static char e_unknown_var[] = N_("E1089: unknown variable: %s"); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
152 |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
153 static void delete_def_function_contents(dfunc_T *dfunc); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
154 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
155 /* |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
156 * Lookup variable "name" in the local scope and return it. |
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
157 * Return NULL if not found. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
158 */ |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
159 static lvar_T * |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
160 lookup_local(char_u *name, size_t len, cctx_T *cctx) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
161 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
162 int idx; |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
163 lvar_T *lvar; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
164 |
19392
5b6f420e7352
patch 8.2.0254: compiler warning for checking size_t to be negative
Bram Moolenaar <Bram@vim.org>
parents:
19388
diff
changeset
|
165 if (len == 0) |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
166 return NULL; |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
167 |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
168 // 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
|
169 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
|
170 { |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
171 lvar = ((lvar_T *)cctx->ctx_locals.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
|
172 if (STRNCMP(name, lvar->lv_name, len) == 0 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
173 && STRLEN(lvar->lv_name) == len) |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
174 { |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
175 lvar->lv_from_outer = FALSE; |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
176 return lvar; |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
177 } |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
178 } |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
179 |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
180 // 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
|
181 if (cctx->ctx_outer != NULL) |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
182 { |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
183 lvar = lookup_local(name, len, cctx->ctx_outer); |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
184 if (lvar != NULL) |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
185 { |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
186 // TODO: are there situations we should not mark the outer scope as |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
187 // used? |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
188 cctx->ctx_outer_used = TRUE; |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
189 lvar->lv_from_outer = TRUE; |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
190 return lvar; |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
191 } |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
192 } |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
193 |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
194 return NULL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
195 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
196 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
197 /* |
20275
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
198 * 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
|
199 * 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
|
200 * 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
|
201 * 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
|
202 * 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
|
203 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
204 static int |
20275
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
205 lookup_arg( |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
206 char_u *name, |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
207 size_t len, |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
208 int *idxp, |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
209 type_T **type, |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
210 int *gen_load_outer, |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
211 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
|
212 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
213 int idx; |
20275
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
214 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
|
215 |
19392
5b6f420e7352
patch 8.2.0254: compiler warning for checking size_t to be negative
Bram Moolenaar <Bram@vim.org>
parents:
19388
diff
changeset
|
216 if (len == 0) |
20275
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
217 return FAIL; |
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_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
|
219 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
220 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
|
221 |
20275
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
222 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
|
223 { |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
224 if (idxp != NULL) |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
225 { |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
226 // 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
|
227 // 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
|
228 *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
|
229 + STACK_FRAME_SIZE) |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
230 + (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
|
231 |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
232 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
|
233 *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
|
234 else |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
235 *type = &t_any; |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
236 } |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
237 return OK; |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
238 } |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
239 } |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
240 |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
241 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
|
242 if (va_name != NULL |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
243 && 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
|
244 { |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
245 if (idxp != NULL) |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
246 { |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
247 // 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
|
248 *idxp = -STACK_FRAME_SIZE - 1; |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
249 *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
|
250 } |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
251 return OK; |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
252 } |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
253 |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
254 if (cctx->ctx_outer != NULL) |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
255 { |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
256 // Lookup the name for an argument of the outer function. |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
257 if (lookup_arg(name, len, idxp, type, gen_load_outer, cctx->ctx_outer) |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
258 == OK) |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
259 { |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
260 *gen_load_outer = TRUE; |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
261 return OK; |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
262 } |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
263 } |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
264 |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
265 return FAIL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
266 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
267 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
268 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
269 * Lookup a variable in the current script. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
270 * 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
|
271 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
272 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
273 lookup_script(char_u *name, size_t len) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
274 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
275 int cc; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
276 hashtab_T *ht = &SCRIPT_VARS(current_sctx.sc_sid); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
277 dictitem_T *di; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
278 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
279 cc = name[len]; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
280 name[len] = NUL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
281 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
|
282 name[len] = cc; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
283 return di == NULL ? FAIL: OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
284 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
285 |
19623
2fee087c94cb
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents:
19597
diff
changeset
|
286 /* |
2fee087c94cb
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents:
19597
diff
changeset
|
287 * Check if "p[len]" is already defined, either in script "import_sid" or in |
2fee087c94cb
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents:
19597
diff
changeset
|
288 * compilation context "cctx". |
2fee087c94cb
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents:
19597
diff
changeset
|
289 * 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
|
290 */ |
2fee087c94cb
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents:
19597
diff
changeset
|
291 int |
21194
afed2045ffc9
patch 8.2.1148: warning for using int instead of size_t
Bram Moolenaar <Bram@vim.org>
parents:
21188
diff
changeset
|
292 check_defined(char_u *p, size_t len, cctx_T *cctx) |
19623
2fee087c94cb
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents:
19597
diff
changeset
|
293 { |
21604
d9c45474cac1
patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents:
21602
diff
changeset
|
294 int c = p[len]; |
d9c45474cac1
patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents:
21602
diff
changeset
|
295 |
d9c45474cac1
patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents:
21602
diff
changeset
|
296 p[len] = NUL; |
19623
2fee087c94cb
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents:
19597
diff
changeset
|
297 if (lookup_script(p, len) == OK |
2fee087c94cb
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents:
19597
diff
changeset
|
298 || (cctx != NULL |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
299 && (lookup_local(p, len, cctx) != NULL |
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
|
300 || lookup_arg(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
|
301 || find_imported(p, len, cctx) != NULL |
d9c45474cac1
patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents:
21602
diff
changeset
|
302 || find_func_even_dead(p, FALSE, cctx) != NULL) |
d9c45474cac1
patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents:
21602
diff
changeset
|
303 { |
d9c45474cac1
patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents:
21602
diff
changeset
|
304 p[len] = c; |
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
|
305 semsg(_(e_already_defined), p); |
19623
2fee087c94cb
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents:
19597
diff
changeset
|
306 return FAIL; |
2fee087c94cb
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents:
19597
diff
changeset
|
307 } |
21604
d9c45474cac1
patch 8.2.1352: Vim9: no error for shadowing a script-local function
Bram Moolenaar <Bram@vim.org>
parents:
21602
diff
changeset
|
308 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
|
309 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
|
310 } |
2fee087c94cb
patch 8.2.0368: Vim9: import that redefines local variable does not fail
Bram Moolenaar <Bram@vim.org>
parents:
19597
diff
changeset
|
311 |
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
|
312 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
313 ///////////////////////////////////////////////////////////////////// |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
314 // 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
|
315 |
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
|
316 #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
|
317 #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
|
318 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
319 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
320 * 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
|
321 * 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
|
322 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
323 static isn_T * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
324 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
|
325 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
326 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
|
327 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
328 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
329 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
|
330 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
|
331 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
332 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
|
333 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
|
334 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
|
335 ++instr->ga_len; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
336 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
337 return isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
338 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
339 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
340 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
341 * 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
|
342 * "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
|
343 * 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
|
344 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
345 static isn_T * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
346 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
|
347 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
348 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
|
349 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
350 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
|
351 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
|
352 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
|
353 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
354 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
355 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
356 * 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
|
357 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
358 static isn_T * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
359 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
|
360 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
361 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
362 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
|
363 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
364 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
|
365 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
366 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
367 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
|
368 return NULL; |
21473
8bcd1ee2630b
patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents:
21469
diff
changeset
|
369 ((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
|
370 ++stack->ga_len; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
371 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
372 return isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
373 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
374 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
375 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
376 * If type at "offset" isn't already VAR_STRING then generate ISN_2STRING. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
377 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
378 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
379 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
|
380 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
381 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
382 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
|
383 type_T **type = ((type_T **)stack->ga_data) + stack->ga_len + offset; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
384 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
385 if ((*type)->tt_type == VAR_STRING) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
386 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
387 *type = &t_string; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
388 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
389 if ((isn = generate_instr(cctx, ISN_2STRING)) == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
390 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
391 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
|
392 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
393 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
394 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
395 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
396 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
397 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
|
398 { |
19922
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19918
diff
changeset
|
399 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
|
400 && (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
|
401 || 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
|
402 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
403 if (*op == '+') |
20982
bb49b5090a9c
patch 8.2.1042: Vim9: cannot put an operator on the next line
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
404 emsg(_("E1051: wrong argument type for +")); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
405 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
406 semsg(_("E1036: %c requires number or float arguments"), *op); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
407 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
408 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
409 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
410 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
411 |
21677
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
412 static int |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
413 generate_add_instr( |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
414 cctx_T *cctx, |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
415 vartype_T vartype, |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
416 type_T *type1, |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
417 type_T *type2) |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
418 { |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
419 isn_T *isn = generate_instr_drop(cctx, |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
420 vartype == VAR_NUMBER ? ISN_OPNR |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
421 : vartype == VAR_LIST ? ISN_ADDLIST |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
422 : vartype == VAR_BLOB ? ISN_ADDBLOB |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
423 #ifdef FEAT_FLOAT |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
424 : vartype == VAR_FLOAT ? ISN_OPFLOAT |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
425 #endif |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
426 : ISN_OPANY, 1); |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
427 |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
428 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
|
429 && type1->tt_type != VAR_ANY |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
430 && type2->tt_type != VAR_ANY |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
431 && check_number_or_float( |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
432 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
|
433 return FAIL; |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
434 |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
435 if (isn != NULL) |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
436 isn->isn_arg.op.op_type = EXPR_ADD; |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
437 return isn == NULL ? FAIL : OK; |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
438 } |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
439 |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
440 /* |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
441 * 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
|
442 * "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
|
443 * 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
|
444 */ |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
445 static vartype_T |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
446 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
|
447 { |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
448 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
|
449 && (type1->tt_type == VAR_NUMBER |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
450 || type1->tt_type == VAR_LIST |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
451 #ifdef FEAT_FLOAT |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
452 || type1->tt_type == VAR_FLOAT |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
453 #endif |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
454 || type1->tt_type == VAR_BLOB)) |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
455 return type1->tt_type; |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
456 return VAR_ANY; |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
457 } |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
458 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
459 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
460 * 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
|
461 * 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
|
462 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
463 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
464 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
|
465 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
466 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
|
467 type_T *type1; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
468 type_T *type2; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
469 vartype_T vartype; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
470 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
471 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
472 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
|
473 |
21677
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
474 // 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
|
475 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
|
476 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
|
477 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
|
478 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
479 switch (*op) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
480 { |
21677
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
481 case '+': |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
482 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
|
483 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
484 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
485 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
486 case '-': |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
487 case '*': |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
488 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
|
489 op) == FAIL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
490 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
491 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
|
492 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
|
493 #ifdef FEAT_FLOAT |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
494 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
|
495 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
|
496 #endif |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
497 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
498 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
|
499 if (isn != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
500 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
|
501 ? 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
|
502 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
503 |
19922
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19918
diff
changeset
|
504 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
|
505 && 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
|
506 || (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
|
507 && 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
|
508 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
509 emsg(_("E1035: % requires number arguments")); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
510 return FAIL; |
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 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
|
513 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
|
514 if (isn != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
515 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
|
516 break; |
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 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
519 // 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
|
520 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
|
521 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
522 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
|
523 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
524 #ifdef FEAT_FLOAT |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
525 // 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
|
526 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
|
527 && (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
|
528 type = &t_float; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
529 #endif |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
530 ((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
|
531 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
532 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
533 return OK; |
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 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
536 /* |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
537 * 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
|
538 * 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
|
539 */ |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
540 static isntype_T |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
541 get_compare_isn(exptype_T exptype, vartype_T type1, vartype_T type2) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
542 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
543 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
|
544 |
19922
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19918
diff
changeset
|
545 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
|
546 type1 = VAR_ANY; |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19918
diff
changeset
|
547 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
|
548 type2 = VAR_ANY; |
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19918
diff
changeset
|
549 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
550 if (type1 == type2) |
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 switch (type1) |
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 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
|
555 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
|
556 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
|
557 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
|
558 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
|
559 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
|
560 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
|
561 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
|
562 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
|
563 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
|
564 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
565 } |
19922
1f42c49c3d29
patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents:
19918
diff
changeset
|
566 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
|
567 || ((type1 == VAR_NUMBER || type1 == VAR_FLOAT) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
568 && (type2 == VAR_NUMBER || type2 ==VAR_FLOAT))) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
569 isntype = ISN_COMPAREANY; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
570 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
571 if ((exptype == EXPR_IS || exptype == EXPR_ISNOT) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
572 && (isntype == ISN_COMPAREBOOL |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
573 || isntype == ISN_COMPARESPECIAL |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
574 || isntype == ISN_COMPARENR |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
575 || isntype == ISN_COMPAREFLOAT)) |
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 semsg(_("E1037: Cannot use \"%s\" with %s"), |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
578 exptype == EXPR_IS ? "is" : "isnot" , vartype_name(type1)); |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
579 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
|
580 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
581 if (isntype == ISN_DROP |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
582 || ((exptype != EXPR_EQUAL && exptype != EXPR_NEQUAL |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
583 && (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
|
584 || type2 == VAR_BOOL || type2 == VAR_SPECIAL))) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
585 || ((exptype != EXPR_EQUAL && exptype != EXPR_NEQUAL |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
586 && exptype != EXPR_IS && exptype != EXPR_ISNOT |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
587 && (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
|
588 || 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
|
589 { |
19583
ba35daca6553
patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents:
19579
diff
changeset
|
590 semsg(_("E1072: Cannot compare %s with %s"), |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
591 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
|
592 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
|
593 } |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
594 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
|
595 } |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
596 |
21251
d1215fcdbca8
patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21248
diff
changeset
|
597 int |
d1215fcdbca8
patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21248
diff
changeset
|
598 check_compare_types(exptype_T type, typval_T *tv1, typval_T *tv2) |
d1215fcdbca8
patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21248
diff
changeset
|
599 { |
d1215fcdbca8
patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21248
diff
changeset
|
600 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
|
601 return FAIL; |
d1215fcdbca8
patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21248
diff
changeset
|
602 return OK; |
d1215fcdbca8
patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21248
diff
changeset
|
603 } |
d1215fcdbca8
patch 8.2.1176: Vim9: not enough type checking in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
21248
diff
changeset
|
604 |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
605 /* |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
606 * 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
|
607 */ |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
608 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
|
609 generate_COMPARE(cctx_T *cctx, exptype_T exptype, int ic) |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
610 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
611 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
|
612 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
|
613 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
|
614 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
|
615 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
|
616 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
617 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
|
618 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
619 // 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
|
620 // 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
|
621 // checking. |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
622 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
|
623 type2 = ((type_T **)stack->ga_data)[stack->ga_len - 1]->tt_type; |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
624 isntype = get_compare_isn(exptype, type1, type2); |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
625 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
|
626 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
627 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
628 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
|
629 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
630 isn->isn_arg.op.op_type = exptype; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
631 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
|
632 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
633 // 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
|
634 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
|
635 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
636 --stack->ga_len; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
637 ((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
|
638 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
639 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
640 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
641 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
642 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
643 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
644 * 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
|
645 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
646 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
647 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
|
648 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
649 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
650 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
|
651 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
652 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
|
653 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
|
654 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
655 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
|
656 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
657 // type becomes bool |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
658 ((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
|
659 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
660 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
661 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
662 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
663 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
664 generate_TYPECHECK(cctx_T *cctx, type_T *vartype, int offset) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
665 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
666 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
667 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
|
668 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
669 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
|
670 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
|
671 return FAIL; |
20207
3c247d9cd6f9
patch 8.2.0659: Vim9: no test for equal func type
Bram Moolenaar <Bram@vim.org>
parents:
20203
diff
changeset
|
672 // TODO: whole type, e.g. for a function also arg and return types |
3c247d9cd6f9
patch 8.2.0659: Vim9: no test for equal func type
Bram Moolenaar <Bram@vim.org>
parents:
20203
diff
changeset
|
673 isn->isn_arg.type.ct_type = vartype->tt_type; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
674 isn->isn_arg.type.ct_off = offset; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
675 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
676 // type becomes vartype |
20255
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20253
diff
changeset
|
677 ((type_T **)stack->ga_data)[stack->ga_len + offset] = vartype; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
678 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
679 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
680 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
681 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
682 /* |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
683 * Check that |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
684 * - "actual" is "expected" type or |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
685 * - "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
|
686 * - return FAIL. |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
687 */ |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
688 static int |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21255
diff
changeset
|
689 need_type( |
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21255
diff
changeset
|
690 type_T *actual, |
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21255
diff
changeset
|
691 type_T *expected, |
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21255
diff
changeset
|
692 int offset, |
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21255
diff
changeset
|
693 cctx_T *cctx, |
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21255
diff
changeset
|
694 int silent) |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
695 { |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
696 if (check_type(expected, actual, FALSE) == OK) |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
697 return OK; |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
698 if (actual->tt_type != VAR_ANY |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
699 && actual->tt_type != VAR_UNKNOWN |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
700 && !(actual->tt_type == VAR_FUNC |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
701 && (actual->tt_member == &t_any || actual->tt_argcount < 0))) |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
702 { |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21255
diff
changeset
|
703 if (!silent) |
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21255
diff
changeset
|
704 type_mismatch(expected, actual); |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
705 return FAIL; |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
706 } |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
707 generate_TYPECHECK(cctx, expected, offset); |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
708 return OK; |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
709 } |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
710 |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
711 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
712 * 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
|
713 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
714 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
715 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
|
716 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
717 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
718 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
719 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
|
720 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
|
721 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
722 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
|
723 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
724 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
725 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
726 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
727 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
728 * 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
|
729 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
730 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
731 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
|
732 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
733 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
734 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
735 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
|
736 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
|
737 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
738 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
|
739 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
740 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
741 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
742 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
743 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
744 * 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
|
745 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
746 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
747 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
|
748 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
749 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
750 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
751 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
|
752 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
|
753 return FAIL; |
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.number = number; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
755 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
756 return OK; |
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 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
759 #ifdef FEAT_FLOAT |
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 * 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
|
762 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
763 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
764 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
|
765 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
766 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
767 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
768 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
|
769 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
|
770 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
771 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
|
772 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
773 return OK; |
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 #endif |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
776 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
777 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
778 * 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
|
779 * Consumes "str". |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
780 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
781 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
782 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
|
783 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
784 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
785 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
786 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
|
787 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
|
788 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
789 isn->isn_arg.string = str; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
790 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
791 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
792 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
793 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
794 /* |
19558
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
795 * 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
|
796 * Consumes "channel". |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
797 */ |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
798 static int |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
799 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
|
800 { |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
801 isn_T *isn; |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
802 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
803 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
|
804 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
|
805 return FAIL; |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
806 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
|
807 |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
808 return OK; |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
809 } |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
810 |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
811 /* |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
812 * 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
|
813 * Consumes "job". |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
814 */ |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
815 static int |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
816 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
|
817 { |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
818 isn_T *isn; |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
819 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
820 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
|
821 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
|
822 return FAIL; |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
823 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
|
824 |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
825 return OK; |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
826 } |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
827 |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
828 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
829 * 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
|
830 * Consumes "blob". |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
831 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
832 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
833 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
|
834 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
835 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
836 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
837 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
|
838 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
|
839 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
840 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
|
841 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
842 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
843 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
844 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
845 /* |
19558
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
846 * 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
|
847 * Consumes "name". |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
848 */ |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
849 static int |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
850 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
|
851 { |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
852 isn_T *isn; |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
853 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
854 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
|
855 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
|
856 return FAIL; |
21473
8bcd1ee2630b
patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents:
21469
diff
changeset
|
857 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
|
858 |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
859 return OK; |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
860 } |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
861 |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
862 /* |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
863 * 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
|
864 */ |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
865 static int |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
866 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
|
867 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
868 isn_T *isn; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
869 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
|
870 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
|
871 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
|
872 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
873 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
|
874 |
21421
0f0fee4122d3
patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents:
21411
diff
changeset
|
875 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
|
876 { |
0f0fee4122d3
patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents:
21411
diff
changeset
|
877 // 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
|
878 emsg(_(e_listreq)); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
879 return FAIL; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
880 } |
21421
0f0fee4122d3
patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents:
21411
diff
changeset
|
881 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
|
882 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
|
883 return FAIL; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
884 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
|
885 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
886 // 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
|
887 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
|
888 return FAIL; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
889 ((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
|
890 ++stack->ga_len; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
891 return OK; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
892 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
893 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
894 /* |
20871
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
895 * 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
|
896 */ |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
897 static int |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
898 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
|
899 { |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
900 isn_T *isn; |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
901 |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
902 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
|
903 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
|
904 return FAIL; |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
905 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
|
906 return OK; |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
907 } |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
908 |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
909 /* |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
910 * 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
|
911 */ |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
912 static int |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
913 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
|
914 { |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
915 isn_T *isn; |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
916 |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
917 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
|
918 |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
919 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
|
920 return FAIL; |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
921 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
|
922 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
|
923 |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
924 return OK; |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
925 } |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
926 |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
927 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
928 * 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
|
929 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
930 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
931 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
|
932 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
933 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
934 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
935 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
|
936 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
|
937 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
938 if (name != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
939 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
|
940 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
941 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
|
942 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
943 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
944 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
945 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
946 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
947 * 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
|
948 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
949 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
950 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
|
951 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
952 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
953 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
954 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
|
955 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
|
956 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
|
957 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
|
958 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
|
959 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
960 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
961 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
962 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
963 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
964 * 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
|
965 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
966 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
967 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
|
968 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
969 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
970 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
971 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
|
972 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
|
973 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
974 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
|
975 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
|
976 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
977 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
978 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
979 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
980 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
981 * 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
|
982 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
983 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
984 generate_LOAD( |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
985 cctx_T *cctx, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
986 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
|
987 int idx, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
988 char_u *name, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
989 type_T *type) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
990 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
991 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
992 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
993 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
|
994 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
|
995 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
996 if (name != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
997 isn->isn_arg.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
|
998 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
999 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
|
1000 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1001 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1002 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1003 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1004 /* |
19960
3c11b9f6fa03
patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
1005 * 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
|
1006 */ |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1007 static int |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1008 generate_LOADV( |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1009 cctx_T *cctx, |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1010 char_u *name, |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1011 int error) |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1012 { |
19960
3c11b9f6fa03
patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
1013 int di_flags; |
3c11b9f6fa03
patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
1014 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
|
1015 type_T *type; |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1016 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
1017 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
|
1018 if (vidx < 0) |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1019 { |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1020 if (error) |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1021 semsg(_(e_var_notfound), name); |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1022 return FAIL; |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1023 } |
21443
66386ca8a69f
patch 8.2.1272: Vim9: type not checked if declaration also assigns value
Bram Moolenaar <Bram@vim.org>
parents:
21441
diff
changeset
|
1024 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
|
1025 |
3c11b9f6fa03
patch 8.2.0536: Vim9: some compilation code not tested
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
1026 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
|
1027 } |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1028 |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1029 /* |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
1030 * Generate an ISN_UNLET instruction. |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
1031 */ |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
1032 static int |
20099
058b41f85bcb
patch 8.2.0605: Vim9: cannot unlet an environment variable
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
1033 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
|
1034 { |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
1035 isn_T *isn; |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
1036 |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
1037 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
|
1038 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
|
1039 return FAIL; |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
1040 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
|
1041 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
|
1042 |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
1043 return OK; |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
1044 } |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
1045 |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
1046 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1047 * 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
|
1048 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1049 static int |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1050 generate_OLDSCRIPT( |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1051 cctx_T *cctx, |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1052 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
|
1053 char_u *name, |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1054 int sid, |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1055 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
|
1056 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1057 isn_T *isn; |
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); |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1060 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
|
1061 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
|
1062 else |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1063 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
|
1064 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
|
1065 return FAIL; |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1066 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
|
1067 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
|
1068 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1069 return OK; |
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 |
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 * 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
|
1074 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1075 static int |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1076 generate_VIM9SCRIPT( |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1077 cctx_T *cctx, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1078 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
|
1079 int sid, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1080 int idx, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1081 type_T *type) |
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 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1084 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
1085 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
|
1086 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
|
1087 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
|
1088 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1089 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
|
1090 if (isn == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1091 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1092 isn->isn_arg.script.script_sid = sid; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1093 isn->isn_arg.script.script_idx = idx; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1094 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1095 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1096 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1097 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1098 * 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
|
1099 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1100 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1101 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
|
1102 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1103 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1104 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
|
1105 type_T *type; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1106 type_T *member; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1107 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
1108 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
|
1109 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
|
1110 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1111 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
|
1112 |
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
|
1113 // get the member type from all the items on the stack. |
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1114 member = get_member_type_from_stack( |
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1115 ((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
|
1116 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
|
1117 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
|
1118 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1119 // 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
|
1120 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
|
1121 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1122 // 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
|
1123 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
|
1124 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1125 ((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
|
1126 ++stack->ga_len; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1127 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1128 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1129 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1130 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1131 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1132 * 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
|
1133 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1134 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1135 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
|
1136 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1137 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1138 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
|
1139 type_T *type; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1140 type_T *member; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1141 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
1142 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
|
1143 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
|
1144 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1145 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
|
1146 |
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
|
1147 member = get_member_type_from_stack( |
571832713efa
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Bram Moolenaar <Bram@vim.org>
parents:
21711
diff
changeset
|
1148 ((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
|
1149 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
|
1150 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
|
1151 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1152 // 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
|
1153 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
|
1154 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1155 // 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
|
1156 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
|
1157 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1158 ((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
|
1159 ++stack->ga_len; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1160 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1161 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1162 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1163 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1164 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1165 * 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
|
1166 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1167 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
|
1168 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
|
1169 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1170 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1171 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
|
1172 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
1173 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
|
1174 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
|
1175 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
|
1176 isn->isn_arg.funcref.fr_func = ufunc->uf_dfunc_idx; |
20247
e46e72aaff74
patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20244
diff
changeset
|
1177 isn->isn_arg.funcref.fr_var_idx = cctx->ctx_closure_count++; |
19181
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 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
|
1180 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
|
1181 ((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
|
1182 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
|
1183 ++stack->ga_len; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1184 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1185 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1186 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1187 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1188 /* |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1189 * Generate an ISN_NEWFUNC instruction. |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1190 */ |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1191 static int |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1192 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
|
1193 { |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1194 isn_T *isn; |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1195 char_u *name; |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1196 |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1197 RETURN_OK_IF_SKIP(cctx); |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1198 name = vim_strsave(lambda_name); |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1199 if (name == NULL) |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1200 return FAIL; |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1201 if ((isn = generate_instr(cctx, ISN_NEWFUNC)) == NULL) |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1202 return FAIL; |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1203 isn->isn_arg.newfunc.nf_lambda = name; |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1204 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
|
1205 |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1206 return OK; |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1207 } |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1208 |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
1209 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1210 * 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
|
1211 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1212 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1213 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
|
1214 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1215 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1216 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
|
1217 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
1218 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
|
1219 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
|
1220 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1221 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
|
1222 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
|
1223 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1224 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
|
1225 --stack->ga_len; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1226 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1227 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1228 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1229 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1230 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1231 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
|
1232 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1233 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1234 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
|
1235 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
1236 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
|
1237 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
|
1238 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1239 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
|
1240 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1241 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
|
1242 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1243 // 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
|
1244 ((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
|
1245 ++stack->ga_len; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1246 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1247 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1248 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1249 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1250 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1251 * 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
|
1252 * "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
|
1253 * 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
|
1254 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1255 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
|
1256 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
|
1257 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1258 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1259 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
|
1260 int argoff; |
19564
06f29b6ea04a
patch 8.2.0339: Vim9: function return type may depend on arguments
Bram Moolenaar <Bram@vim.org>
parents:
19562
diff
changeset
|
1261 type_T *argtypes[MAX_FUNC_ARGS]; |
06f29b6ea04a
patch 8.2.0339: Vim9: function return type may depend on arguments
Bram Moolenaar <Bram@vim.org>
parents:
19562
diff
changeset
|
1262 int i; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1263 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
1264 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
|
1265 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
|
1266 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
|
1267 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1268 |
21232
3f14e0d4a4dd
patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents:
21220
diff
changeset
|
1269 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
|
1270 { |
3f14e0d4a4dd
patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents:
21220
diff
changeset
|
1271 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
|
1272 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
|
1273 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
|
1274 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
|
1275 } |
3f14e0d4a4dd
patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents:
21220
diff
changeset
|
1276 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1277 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
|
1278 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1279 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
|
1280 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
|
1281 |
19564
06f29b6ea04a
patch 8.2.0339: Vim9: function return type may depend on arguments
Bram Moolenaar <Bram@vim.org>
parents:
19562
diff
changeset
|
1282 for (i = 0; i < argcount; ++i) |
06f29b6ea04a
patch 8.2.0339: Vim9: function return type may depend on arguments
Bram Moolenaar <Bram@vim.org>
parents:
19562
diff
changeset
|
1283 argtypes[i] = ((type_T **)stack->ga_data)[stack->ga_len - argcount + i]; |
06f29b6ea04a
patch 8.2.0339: Vim9: function return type may depend on arguments
Bram Moolenaar <Bram@vim.org>
parents:
19562
diff
changeset
|
1284 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1285 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
|
1286 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
|
1287 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1288 ((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
|
1289 internal_func_ret_type(func_idx, argcount, argtypes); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1290 ++stack->ga_len; // add return value |
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 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1293 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1294 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1295 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1296 * 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
|
1297 * 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
|
1298 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1299 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
|
1300 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
|
1301 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1302 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1303 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
|
1304 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
|
1305 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
|
1306 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
1307 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
|
1308 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
|
1309 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1310 semsg(_(e_toomanyarg), ufunc->uf_name); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1311 return FAIL; |
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 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
|
1314 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1315 semsg(_(e_toofewarg), ufunc->uf_name); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1316 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1317 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1318 |
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
|
1319 if (ufunc->uf_def_status != UF_NOT_COMPILED) |
19944
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
1320 { |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
1321 int i; |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
1322 |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
1323 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
|
1324 { |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
1325 type_T *expected; |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
1326 type_T *actual; |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
1327 |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
1328 if (i < regular_args) |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
1329 { |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
1330 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
|
1331 continue; |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
1332 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
|
1333 } |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
1334 else |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
1335 expected = ufunc->uf_va_type->tt_member; |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
1336 actual = ((type_T **)stack->ga_data)[stack->ga_len - argcount + i]; |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21255
diff
changeset
|
1337 if (need_type(actual, expected, -argcount + i, cctx, TRUE) == FAIL) |
19944
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
1338 { |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
1339 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
|
1340 return FAIL; |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
1341 } |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
1342 } |
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
|
1343 if (ufunc->uf_def_status == UF_TO_BE_COMPILED) |
21693
4e4fd845553d
patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents:
21691
diff
changeset
|
1344 if (compile_def_function(ufunc, ufunc->uf_ret_type == NULL, NULL) |
4e4fd845553d
patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents:
21691
diff
changeset
|
1345 == FAIL) |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20419
diff
changeset
|
1346 return FAIL; |
19944
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
1347 } |
3055cd26e139
patch 8.2.0528: Vim9: function arguments insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19942
diff
changeset
|
1348 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1349 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
|
1350 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
|
1351 : 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
|
1352 return FAIL; |
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
|
1353 if (ufunc->uf_def_status != UF_NOT_COMPILED) |
19181
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->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
|
1356 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
|
1357 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1358 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1359 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1360 // 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
|
1361 // 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
|
1362 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
|
1363 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
|
1364 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1365 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1366 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
|
1367 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
|
1368 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1369 // add return value |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1370 ((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
|
1371 ++stack->ga_len; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1372 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1373 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1374 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1375 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1376 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1377 * 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
|
1378 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1379 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1380 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
|
1381 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1382 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1383 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
|
1384 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
1385 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
|
1386 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
|
1387 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1388 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
|
1389 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
|
1390 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1391 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
|
1392 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
|
1393 return FAIL; |
2a63b7f5802a
patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents:
19285
diff
changeset
|
1394 // add return value |
2a63b7f5802a
patch 8.2.0206: calling Vim9 function using default argument fails
Bram Moolenaar <Bram@vim.org>
parents:
19285
diff
changeset
|
1395 ((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
|
1396 ++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
|
1397 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1398 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1399 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1400 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1401 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1402 * 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
|
1403 * "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
|
1404 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1405 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
|
1406 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
|
1407 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
|
1408 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
|
1409 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
|
1410 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
|
1411 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
|
1412 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1413 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1414 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
|
1415 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
|
1416 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
1417 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
|
1418 |
20203
5a397db2c1ed
patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
1419 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
|
1420 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
|
1421 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
|
1422 { |
ab8c8fd0f868
patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20279
diff
changeset
|
1423 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
|
1424 { |
ab8c8fd0f868
patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20279
diff
changeset
|
1425 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
|
1426 |
ab8c8fd0f868
patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20279
diff
changeset
|
1427 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
|
1428 { |
ab8c8fd0f868
patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20279
diff
changeset
|
1429 semsg(_(e_toofewarg), "[reference]"); |
ab8c8fd0f868
patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20279
diff
changeset
|
1430 return FAIL; |
ab8c8fd0f868
patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20279
diff
changeset
|
1431 } |
ab8c8fd0f868
patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20279
diff
changeset
|
1432 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
|
1433 { |
ab8c8fd0f868
patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20279
diff
changeset
|
1434 semsg(_(e_toomanyarg), "[reference]"); |
ab8c8fd0f868
patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20279
diff
changeset
|
1435 return FAIL; |
ab8c8fd0f868
patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20279
diff
changeset
|
1436 } |
ab8c8fd0f868
patch 8.2.0696: Vim9: nested function does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
20279
diff
changeset
|
1437 } |
20203
5a397db2c1ed
patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
1438 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
|
1439 } |
20203
5a397db2c1ed
patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
1440 else |
5a397db2c1ed
patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
1441 { |
5a397db2c1ed
patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
1442 semsg(_("E1085: Not a callable type: %s"), name); |
5a397db2c1ed
patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
1443 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
|
1444 } |
5a397db2c1ed
patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents:
20189
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 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
|
1447 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1448 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
|
1449 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
|
1450 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1451 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
|
1452 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1453 // 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
|
1454 ((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
|
1455 |
19862
846fbbacce3a
patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19860
diff
changeset
|
1456 // 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
|
1457 // the return value. |
846fbbacce3a
patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19860
diff
changeset
|
1458 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
|
1459 return FAIL; |
846fbbacce3a
patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19860
diff
changeset
|
1460 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1461 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1462 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1463 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1464 /* |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
1465 * 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
|
1466 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1467 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
|
1468 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
|
1469 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1470 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1471 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
|
1472 type_T *type; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1473 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
1474 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
|
1475 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
|
1476 return FAIL; |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20538
diff
changeset
|
1477 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
|
1478 |
19461
08ef11a81daa
patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents:
19455
diff
changeset
|
1479 // 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
|
1480 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
|
1481 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
|
1482 { |
08ef11a81daa
patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents:
19455
diff
changeset
|
1483 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
|
1484 return FAIL; |
08ef11a81daa
patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents:
19455
diff
changeset
|
1485 } |
08ef11a81daa
patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents:
19455
diff
changeset
|
1486 // 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
|
1487 if (type->tt_type == VAR_DICT) |
08ef11a81daa
patch 8.2.0288: Vim9: some float and blob operators not tested
Bram Moolenaar <Bram@vim.org>
parents:
19455
diff
changeset
|
1488 ((type_T **)stack->ga_data)[stack->ga_len - 1] = type->tt_member; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1489 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1490 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1491 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1492 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1493 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1494 * 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
|
1495 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1496 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1497 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
|
1498 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1499 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1500 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
1501 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
|
1502 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
|
1503 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1504 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
|
1505 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
|
1506 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1507 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1508 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1509 |
19528
3b026343f398
patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents:
19521
diff
changeset
|
1510 /* |
20142
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
1511 * 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
|
1512 */ |
3b026343f398
patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents:
19521
diff
changeset
|
1513 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
|
1514 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
|
1515 { |
3b026343f398
patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents:
19521
diff
changeset
|
1516 isn_T *isn; |
3b026343f398
patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents:
19521
diff
changeset
|
1517 |
20142
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
1518 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
|
1519 return FAIL; |
3b026343f398
patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents:
19521
diff
changeset
|
1520 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
|
1521 |
3b026343f398
patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents:
19521
diff
changeset
|
1522 return OK; |
3b026343f398
patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents:
19521
diff
changeset
|
1523 } |
3b026343f398
patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents:
19521
diff
changeset
|
1524 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1525 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1526 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
|
1527 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1528 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1529 |
19587
e61dc51ab9b4
patch 8.2.0350: Vim9: expression tests don't use recognized constants
Bram Moolenaar <Bram@vim.org>
parents:
19583
diff
changeset
|
1530 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
|
1531 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
|
1532 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1533 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
|
1534 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1535 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1536 |
20170
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
1537 static int |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
1538 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
|
1539 { |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
1540 isn_T *isn; |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
1541 |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
1542 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
|
1543 return FAIL; |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
1544 isn->isn_arg.number = count; |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
1545 return OK; |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
1546 } |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
1547 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1548 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1549 * 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
|
1550 * 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
|
1551 */ |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
1552 static lvar_T * |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1553 reserve_local(cctx_T *cctx, char_u *name, size_t len, int isConst, type_T *type) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1554 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1555 lvar_T *lvar; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1556 |
20275
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
1557 if (lookup_arg(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
|
1558 { |
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
|
1559 emsg_namelen(_(e_used_as_arg), name, (int)len); |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
1560 return NULL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1561 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1562 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1563 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
|
1564 return NULL; |
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
1565 lvar = ((lvar_T *)cctx->ctx_locals.ga_data) + cctx->ctx_locals.ga_len++; |
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
1566 |
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
1567 // 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
|
1568 // 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
|
1569 // 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
|
1570 // 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
|
1571 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
|
1572 |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20538
diff
changeset
|
1573 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
|
1574 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
|
1575 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
|
1576 |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
1577 return lvar; |
19181
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 /* |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1581 * 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
|
1582 */ |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1583 static void |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1584 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
|
1585 { |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1586 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
|
1587 { |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1588 int idx; |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1589 lvar_T *lvar; |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1590 |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1591 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
|
1592 { |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1593 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
|
1594 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
|
1595 } |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1596 } |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1597 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
|
1598 } |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1599 |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1600 /* |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1601 * 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
|
1602 */ |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1603 static void |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
1604 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
|
1605 { |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1606 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
|
1607 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
|
1608 } |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1609 |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1610 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1611 * Find "name" in script-local items of script "sid". |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1612 * 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
|
1613 * If found but not in "sn_var_vals" returns -1. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1614 * If not found returns -2. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1615 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1616 int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1617 get_script_item_idx(int sid, char_u *name, int check_writable) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1618 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1619 hashtab_T *ht; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1620 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
|
1621 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
|
1622 int idx; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1623 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1624 // 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
|
1625 if (sid <= 0 || sid > script_items.ga_len) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1626 return -1; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1627 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
|
1628 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
|
1629 if (di == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1630 return -2; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1631 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1632 // 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
|
1633 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
|
1634 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1635 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
|
1636 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1637 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
|
1638 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1639 if (check_writable && sv->sv_const) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1640 semsg(_(e_readonlyvar), name); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1641 return idx; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1642 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1643 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1644 return -1; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1645 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1646 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1647 /* |
20840
0600ab7b9f09
patch 8.2.0972: Vim9 script variable declarations need a type
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1648 * 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
|
1649 * NULL. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1650 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1651 imported_T * |
19285
86665583dc83
patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents:
19283
diff
changeset
|
1652 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
|
1653 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1654 int idx; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1655 |
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
|
1656 if (current_sctx.sc_sid <= 0) |
8fb0e507491d
patch 8.2.1106: crash when trying to use s: variable in typed command
Bram Moolenaar <Bram@vim.org>
parents:
21040
diff
changeset
|
1657 return NULL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1658 if (cctx != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1659 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
|
1660 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1661 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
|
1662 + idx; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1663 |
19285
86665583dc83
patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents:
19283
diff
changeset
|
1664 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
|
1665 : 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
|
1666 && 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
|
1667 return import; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1668 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1669 |
21699
1b96535705a0
patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents:
21693
diff
changeset
|
1670 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
|
1671 } |
1b96535705a0
patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents:
21693
diff
changeset
|
1672 |
1b96535705a0
patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents:
21693
diff
changeset
|
1673 imported_T * |
1b96535705a0
patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents:
21693
diff
changeset
|
1674 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
|
1675 { |
1b96535705a0
patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents:
21693
diff
changeset
|
1676 scriptitem_T *si = SCRIPT_ITEM(sid); |
1b96535705a0
patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents:
21693
diff
changeset
|
1677 int idx; |
1b96535705a0
patch 8.2.1399: Vim9: may find imported item in wrong script
Bram Moolenaar <Bram@vim.org>
parents:
21693
diff
changeset
|
1678 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1679 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
|
1680 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1681 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
|
1682 |
19285
86665583dc83
patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents:
19283
diff
changeset
|
1683 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
|
1684 : 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
|
1685 && 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
|
1686 return import; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1687 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1688 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1689 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1690 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1691 /* |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1692 * 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
|
1693 */ |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1694 static void |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1695 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
|
1696 { |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1697 int idx; |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1698 |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1699 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
|
1700 { |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1701 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
|
1702 |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1703 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
|
1704 } |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1705 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
|
1706 } |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1707 |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
1708 /* |
20955
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
1709 * Return TRUE if "p" points at a "#" but not at "#{". |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
1710 */ |
21385
54a304e4dc57
patch 8.2.1243: Vim9: cannot have a comment line halfway a list
Bram Moolenaar <Bram@vim.org>
parents:
21383
diff
changeset
|
1711 int |
21353
fb8c8fcb7b60
patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents:
21345
diff
changeset
|
1712 vim9_comment_start(char_u *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
|
1713 { |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
1714 return p[0] == '#' && p[1] != '{'; |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
1715 } |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
1716 |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
1717 /* |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
1718 * 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
|
1719 * 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
|
1720 * 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
|
1721 */ |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21202
diff
changeset
|
1722 char_u * |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21202
diff
changeset
|
1723 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
|
1724 { |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
1725 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
|
1726 |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
1727 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
|
1728 { |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
1729 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
|
1730 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
|
1731 |
d561e3c6cd65
patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents:
20966
diff
changeset
|
1732 if (line == NULL) |
d561e3c6cd65
patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents:
20966
diff
changeset
|
1733 break; |
d561e3c6cd65
patch 8.2.1037: Vim9: crash when using line continuation inside :def
Bram Moolenaar <Bram@vim.org>
parents:
20966
diff
changeset
|
1734 p = skipwhite(line); |
21353
fb8c8fcb7b60
patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents:
21345
diff
changeset
|
1735 if (*p != NUL && !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
|
1736 return p; |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
1737 } |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
1738 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
|
1739 } |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
1740 |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
1741 /* |
20988
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
1742 * 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
|
1743 * 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
|
1744 * 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
|
1745 * 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
|
1746 */ |
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
1747 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
|
1748 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
|
1749 { |
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
1750 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
|
1751 |
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
1752 *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
|
1753 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
|
1754 { |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21202
diff
changeset
|
1755 *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
|
1756 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
|
1757 return *nextp; |
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
1758 } |
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
1759 return p; |
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
1760 } |
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
1761 |
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
1762 /* |
20011
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1763 * 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
|
1764 * 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
|
1765 * 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
|
1766 */ |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21202
diff
changeset
|
1767 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
|
1768 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
|
1769 { |
20059
de756b3f4dee
patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents:
20055
diff
changeset
|
1770 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
|
1771 |
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1772 do |
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1773 { |
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1774 ++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
|
1775 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
|
1776 { |
de756b3f4dee
patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents:
20055
diff
changeset
|
1777 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
|
1778 break; |
20059
de756b3f4dee
patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents:
20055
diff
changeset
|
1779 } |
20011
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1780 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
|
1781 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
|
1782 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
|
1783 } 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
|
1784 || (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
|
1785 return line; |
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1786 } |
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1787 |
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1788 /* |
20013
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
1789 * 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
|
1790 * 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
|
1791 * 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
|
1792 */ |
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
1793 static int |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
1794 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
|
1795 { |
21353
fb8c8fcb7b60
patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents:
21345
diff
changeset
|
1796 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
|
1797 { |
20955
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
1798 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
|
1799 |
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
1800 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
|
1801 return FAIL; |
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
1802 *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
|
1803 } |
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
1804 return OK; |
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
1805 } |
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
1806 |
21248
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
1807 /* |
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
1808 * 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
|
1809 */ |
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
1810 static int |
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
1811 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
|
1812 { |
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
1813 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
|
1814 { |
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
1815 emsg(_("E1097: line incomplete")); |
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
1816 return FAIL; |
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
1817 } |
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
1818 return OK; |
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
1819 } |
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
1820 |
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
1821 |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1822 // 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
|
1823 // 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
|
1824 // 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
|
1825 // 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
|
1826 // 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
|
1827 // 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
|
1828 #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
|
1829 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
|
1830 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
|
1831 int pp_used; // active entries in pp_tv[] |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1832 } 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
|
1833 |
20336
2fd980fb9ab3
patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents:
20334
diff
changeset
|
1834 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
|
1835 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
|
1836 |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1837 /* |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1838 * 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
|
1839 * "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
|
1840 * 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
|
1841 */ |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1842 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
|
1843 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
|
1844 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1845 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
|
1846 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1847 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
|
1848 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1849 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
|
1850 break; |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1851 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
|
1852 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
|
1853 break; |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1854 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
|
1855 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
|
1856 break; |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1857 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
|
1858 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
|
1859 break; |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1860 #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
|
1861 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
|
1862 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
|
1863 break; |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1864 #endif |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1865 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
|
1866 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
|
1867 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
|
1868 break; |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1869 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
|
1870 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
|
1871 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
|
1872 break; |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1873 default: |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1874 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
|
1875 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
|
1876 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
|
1877 } |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1878 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
|
1879 } |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1880 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
|
1881 } |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1882 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1883 /* |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1884 * 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
|
1885 */ |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1886 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
|
1887 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
|
1888 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1889 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
|
1890 int ret = OK; |
20332
a407e243c55c
patch 8.2.0721: Vim9: leaking memory when skipping
Bram Moolenaar <Bram@vim.org>
parents:
20328
diff
changeset
|
1891 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
|
1892 |
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
|
1893 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
|
1894 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
|
1895 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
|
1896 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
|
1897 ppconst->pp_used = 0; |
20332
a407e243c55c
patch 8.2.0721: Vim9: leaking memory when skipping
Bram Moolenaar <Bram@vim.org>
parents:
20328
diff
changeset
|
1898 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
|
1899 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
|
1900 } |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1901 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1902 /* |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1903 * 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
|
1904 */ |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1905 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
|
1906 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
|
1907 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1908 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
|
1909 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1910 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
|
1911 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
|
1912 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
|
1913 } |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
1914 |
20013
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
1915 /* |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
1916 * 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
|
1917 * leading "s:". |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
1918 * 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
|
1919 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1920 static int |
19509
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1921 compile_load_scriptvar( |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1922 cctx_T *cctx, |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1923 char_u *name, // variable NUL terminated |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1924 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
|
1925 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
|
1926 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
|
1927 { |
19191
133ef7ba4e4e
patch 8.2.0154: reallocating the list of scripts is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
1928 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1929 int idx = get_script_item_idx(current_sctx.sc_sid, name, FALSE); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1930 imported_T *import; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1931 |
19451
b26e96f7c12f
patch 8.2.0283: Vim9: failing to load script var not tested
Bram Moolenaar <Bram@vim.org>
parents:
19437
diff
changeset
|
1932 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
|
1933 { |
19451
b26e96f7c12f
patch 8.2.0283: Vim9: failing to load script var not tested
Bram Moolenaar <Bram@vim.org>
parents:
19437
diff
changeset
|
1934 // 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
|
1935 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
|
1936 &t_any); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1937 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1938 if (idx >= 0) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1939 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1940 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
|
1941 |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
1942 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
|
1943 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
|
1944 return OK; |
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 |
19285
86665583dc83
patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents:
19283
diff
changeset
|
1947 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
|
1948 if (import != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1949 { |
19509
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1950 if (import->imp_all) |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1951 { |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1952 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
|
1953 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
|
1954 int cc; |
19509
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1955 ufunc_T *ufunc; |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1956 type_T *type; |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1957 |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1958 // 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
|
1959 if (*p != '.') |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1960 { |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1961 semsg(_("E1060: expected dot after name: %s"), start); |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1962 return FAIL; |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1963 } |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1964 ++p; |
19818
c1c88b333481
patch 8.2.0465: Vim9: dead code and wrong return type
Bram Moolenaar <Bram@vim.org>
parents:
19785
diff
changeset
|
1965 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
|
1966 { |
c1c88b333481
patch 8.2.0465: Vim9: dead code and wrong return type
Bram Moolenaar <Bram@vim.org>
parents:
19785
diff
changeset
|
1967 emsg(_("E1074: no white space allowed after dot")); |
c1c88b333481
patch 8.2.0465: Vim9: dead code and wrong return type
Bram Moolenaar <Bram@vim.org>
parents:
19785
diff
changeset
|
1968 return FAIL; |
c1c88b333481
patch 8.2.0465: Vim9: dead code and wrong return type
Bram Moolenaar <Bram@vim.org>
parents:
19785
diff
changeset
|
1969 } |
19509
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1970 |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
1971 // 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
|
1972 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
|
1973 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
|
1974 ++p; |
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
1975 cc = *p; |
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
1976 *p = NUL; |
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
1977 |
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
1978 idx = find_exported(import->imp_sid, exp_name, &ufunc, &type); |
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
1979 *p = cc; |
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
1980 p = skipwhite(p); |
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
1981 |
19509
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1982 // TODO: what if it is a function? |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1983 if (idx < 0) |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1984 return FAIL; |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1985 *end = p; |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1986 |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1987 generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT, |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1988 import->imp_sid, |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1989 idx, |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1990 type); |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1991 } |
21473
8bcd1ee2630b
patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents:
21469
diff
changeset
|
1992 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
|
1993 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
|
1994 else |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1995 generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT, |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1996 import->imp_sid, |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1997 import->imp_var_vals_idx, |
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
1998 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
|
1999 return OK; |
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 |
19530
48e71f948360
patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents:
19528
diff
changeset
|
2002 if (error) |
48e71f948360
patch 8.2.0322: Vim9: error checks not tested
Bram Moolenaar <Bram@vim.org>
parents:
19528
diff
changeset
|
2003 semsg(_("E1050: Item not found: %s"), name); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2004 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2005 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2006 |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
2007 static int |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
2008 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
|
2009 { |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20174
diff
changeset
|
2010 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
|
2011 |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
2012 if (ufunc == NULL) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
2013 return FAIL; |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
2014 |
21469
4d156aead799
patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents:
21467
diff
changeset
|
2015 // Need to compile any default values to get the argument types. |
4d156aead799
patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents:
21467
diff
changeset
|
2016 if (ufunc->uf_def_status == UF_TO_BE_COMPILED) |
4d156aead799
patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents:
21467
diff
changeset
|
2017 if (compile_def_function(ufunc, TRUE, NULL) == FAIL) |
4d156aead799
patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents:
21467
diff
changeset
|
2018 return FAIL; |
21473
8bcd1ee2630b
patch 8.2.1287: Vim9: crash when using an imported function
Bram Moolenaar <Bram@vim.org>
parents:
21469
diff
changeset
|
2019 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
|
2020 } |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
2021 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2022 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2023 * 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
|
2024 * "end" points to just after the name. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2025 * 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
|
2026 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2027 static int |
19509
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
2028 compile_load(char_u **arg, char_u *end_arg, cctx_T *cctx, int error) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2029 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2030 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
|
2031 char_u *name = NULL; |
19509
17f0d6dc6a73
patch 8.2.0312: Vim9: insufficient script tests
Bram Moolenaar <Bram@vim.org>
parents:
19481
diff
changeset
|
2032 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
|
2033 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
|
2034 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
|
2035 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2036 if (*(*arg + 1) == ':') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2037 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2038 // load namespaced variable |
19822
fc3cdc819d80
patch 8.2.0467: Vim9: some errors are not tested
Bram Moolenaar <Bram@vim.org>
parents:
19818
diff
changeset
|
2039 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
|
2040 { |
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
|
2041 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
|
2042 |
5cb6e676defd
patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents:
21393
diff
changeset
|
2043 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
|
2044 { |
5cb6e676defd
patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents:
21393
diff
changeset
|
2045 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
|
2046 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
|
2047 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
|
2048 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
|
2049 default: |
5cb6e676defd
patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents:
21393
diff
changeset
|
2050 semsg(_(e_namespace), *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
|
2051 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
|
2052 } |
5cb6e676defd
patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents:
21393
diff
changeset
|
2053 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
|
2054 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
|
2055 res = OK; |
19822
fc3cdc819d80
patch 8.2.0467: Vim9: some errors are not tested
Bram Moolenaar <Bram@vim.org>
parents:
19818
diff
changeset
|
2056 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2057 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2058 { |
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
|
2059 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
|
2060 |
5cb6e676defd
patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents:
21393
diff
changeset
|
2061 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
|
2062 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
|
2063 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
|
2064 |
5cb6e676defd
patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents:
21393
diff
changeset
|
2065 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
|
2066 { |
5cb6e676defd
patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents:
21393
diff
changeset
|
2067 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
|
2068 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
|
2069 case 's': res = compile_load_scriptvar(cctx, name, |
5cb6e676defd
patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents:
21393
diff
changeset
|
2070 NULL, NULL, error); |
5cb6e676defd
patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents:
21393
diff
changeset
|
2071 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
|
2072 case 'g': isn_type = ISN_LOADG; 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
|
2073 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
|
2074 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
|
2075 case 'b': isn_type = ISN_LOADB; 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
|
2076 default: semsg(_(e_namespace), *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
|
2077 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
|
2078 } |
5cb6e676defd
patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents:
21393
diff
changeset
|
2079 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
|
2080 { |
5cb6e676defd
patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents:
21393
diff
changeset
|
2081 // 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
|
2082 // variables can be defined later, thus we don't check if it |
5cb6e676defd
patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents:
21393
diff
changeset
|
2083 // exists, give error at runtime. |
5cb6e676defd
patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents:
21393
diff
changeset
|
2084 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
|
2085 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2086 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2087 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2088 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2089 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2090 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
|
2091 int idx; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2092 int gen_load = FALSE; |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
2093 int gen_load_outer = FALSE; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2094 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2095 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
|
2096 if (name == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2097 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2098 |
20275
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
2099 if (lookup_arg(*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
|
2100 { |
20275
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
2101 if (!gen_load_outer) |
350bb78345ba
patch 8.2.0693: closure using argument not tested
Bram Moolenaar <Bram@vim.org>
parents:
20259
diff
changeset
|
2102 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
|
2103 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2104 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2105 { |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
2106 lvar_T *lvar = lookup_local(*arg, len, cctx); |
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
2107 |
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
2108 if (lvar != NULL) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2109 { |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
2110 type = lvar->lv_type; |
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
2111 idx = lvar->lv_idx; |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
2112 if (lvar->lv_from_outer) |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
2113 gen_load_outer = TRUE; |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
2114 else |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
2115 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
|
2116 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2117 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2118 { |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2119 // "var" can be script-local even without using "s:" if it |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2120 // already exists. |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2121 if (SCRIPT_ITEM(current_sctx.sc_sid)->sn_version |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2122 == SCRIPT_VERSION_VIM9 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2123 || lookup_script(*arg, len) == OK) |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2124 res = compile_load_scriptvar(cctx, name, *arg, &end, |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2125 FALSE); |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2126 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2127 // When the name starts with an uppercase letter or "x:" it |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2128 // can be a user defined function. |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2129 if (res == FAIL && (ASCII_ISUPPER(*name) || name[1] == ':')) |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2130 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
|
2131 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2132 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2133 if (gen_load) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2134 res = generate_LOAD(cctx, ISN_LOAD, idx, NULL, type); |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
2135 if (gen_load_outer) |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
2136 res = generate_LOAD(cctx, ISN_LOADOUTER, idx, NULL, type); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2137 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2138 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2139 *arg = end; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2140 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2141 theend: |
19818
c1c88b333481
patch 8.2.0465: Vim9: dead code and wrong return type
Bram Moolenaar <Bram@vim.org>
parents:
19785
diff
changeset
|
2142 if (res == FAIL && error && called_emsg == prev_called_emsg) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2143 semsg(_(e_var_notfound), name); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2144 vim_free(name); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2145 return res; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2146 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2147 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2148 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2149 * 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
|
2150 * "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
|
2151 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2152 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2153 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
|
2154 { |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
2155 char_u *p = *arg; |
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
2156 char_u *whitep = *arg; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2157 |
20011
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2158 for (;;) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2159 { |
20955
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
2160 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
|
2161 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
|
2162 if (*p == ')') |
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2163 { |
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2164 *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
|
2165 return OK; |
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2166 } |
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2167 |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2168 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
|
2169 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2170 ++*argcount; |
19437
5d34ae66118e
patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents:
19423
diff
changeset
|
2171 |
5d34ae66118e
patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents:
19423
diff
changeset
|
2172 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
|
2173 { |
19904
bd4f91762d0f
patch 8.2.0508: Vim9: func and partial types not done yet
Bram Moolenaar <Bram@vim.org>
parents:
19896
diff
changeset
|
2174 semsg(_(e_no_white_before), ","); |
19437
5d34ae66118e
patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents:
19423
diff
changeset
|
2175 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
|
2176 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2177 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
|
2178 { |
5d34ae66118e
patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents:
19423
diff
changeset
|
2179 ++p; |
20011
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2180 if (*p != NUL && !VIM_ISWHITE(*p)) |
19904
bd4f91762d0f
patch 8.2.0508: Vim9: func and partial types not done yet
Bram Moolenaar <Bram@vim.org>
parents:
19896
diff
changeset
|
2181 semsg(_(e_white_after), ","); |
19437
5d34ae66118e
patch 8.2.0276: Vim9: not allowing space before ")" in function call
Bram Moolenaar <Bram@vim.org>
parents:
19423
diff
changeset
|
2182 } |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
2183 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
|
2184 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
|
2185 } |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
2186 failret: |
20011
628011800942
patch 8.2.0561: Vim9: cannot split function call in multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2187 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
|
2188 return FAIL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2189 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2190 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2191 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2192 * 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
|
2193 * "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
|
2194 * "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
|
2195 * Instructions: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2196 * EVAL arg1 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2197 * EVAL arg2 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2198 * BCALL / DCALL / UCALL |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2199 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2200 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
|
2201 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
|
2202 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
|
2203 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
|
2204 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
|
2205 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
|
2206 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
|
2207 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2208 char_u *name = *arg; |
19257
5aab9c306181
patch 8.2.0187: reduntant code
Bram Moolenaar <Bram@vim.org>
parents:
19253
diff
changeset
|
2209 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
|
2210 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
|
2211 char_u namebuf[100]; |
19330
9c8b803fe598
patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents:
19328
diff
changeset
|
2212 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
|
2213 char_u *tofree = NULL; |
9c8b803fe598
patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents:
19328
diff
changeset
|
2214 int error = FCERR_NONE; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2215 ufunc_T *ufunc; |
19330
9c8b803fe598
patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents:
19328
diff
changeset
|
2216 int res = FAIL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2217 |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2218 // 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
|
2219 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
|
2220 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2221 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
|
2222 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
|
2223 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2224 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
|
2225 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
|
2226 (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
|
2227 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
|
2228 (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
|
2229 s = skipwhite(s); |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2230 if (*s == ')' && argvars[0].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
|
2231 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2232 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
|
2233 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2234 *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
|
2235 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
|
2236 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
|
2237 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
|
2238 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
|
2239 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
|
2240 ++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
|
2241 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
|
2242 } |
20332
a407e243c55c
patch 8.2.0721: Vim9: leaking memory when skipping
Bram Moolenaar <Bram@vim.org>
parents:
20328
diff
changeset
|
2243 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
|
2244 } |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2245 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2246 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
|
2247 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
|
2248 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2249 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
|
2250 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2251 semsg(_("E1011: name too long: %s"), name); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2252 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2253 } |
19330
9c8b803fe598
patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents:
19328
diff
changeset
|
2254 vim_strncpy(namebuf, *arg, varlen); |
9c8b803fe598
patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents:
19328
diff
changeset
|
2255 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
|
2256 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2257 *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
|
2258 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
|
2259 goto theend; |
9c8b803fe598
patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents:
19328
diff
changeset
|
2260 |
9c8b803fe598
patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents:
19328
diff
changeset
|
2261 if (ASCII_ISLOWER(*name) && name[1] != ':') |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2262 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2263 int idx; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2264 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2265 // builtin function |
19330
9c8b803fe598
patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents:
19328
diff
changeset
|
2266 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
|
2267 if (idx >= 0) |
21232
3f14e0d4a4dd
patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents:
21220
diff
changeset
|
2268 res = generate_BCALL(cctx, idx, argcount, argcount_init == 1); |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
2269 else |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
2270 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
|
2271 goto theend; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2272 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2273 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2274 // If we can find the function by name generate the right call. |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20174
diff
changeset
|
2275 ufunc = find_func(name, FALSE, cctx); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2276 if (ufunc != NULL) |
19330
9c8b803fe598
patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents:
19328
diff
changeset
|
2277 { |
9c8b803fe598
patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents:
19328
diff
changeset
|
2278 res = generate_CALL(cctx, ufunc, argcount); |
9c8b803fe598
patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents:
19328
diff
changeset
|
2279 goto theend; |
9c8b803fe598
patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents:
19328
diff
changeset
|
2280 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2281 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2282 // 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
|
2283 // Not for g:Func(), we don't know if it is a variable or not. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2284 p = namebuf; |
20079
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20059
diff
changeset
|
2285 if (STRNCMP(namebuf, "g:", 2) != 0 |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20059
diff
changeset
|
2286 && compile_load(&p, namebuf + varlen, cctx, FALSE) == OK) |
19330
9c8b803fe598
patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents:
19328
diff
changeset
|
2287 { |
20203
5a397db2c1ed
patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
2288 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
|
2289 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
|
2290 |
5a397db2c1ed
patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
2291 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
|
2292 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
|
2293 goto theend; |
9c8b803fe598
patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents:
19328
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 |
20140
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20138
diff
changeset
|
2296 // 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
|
2297 // runtime. Also handles a FuncRef at runtime. |
20140
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20138
diff
changeset
|
2298 if (STRNCMP(namebuf, "g:", 2) == 0) |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20138
diff
changeset
|
2299 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
|
2300 else |
39a18a0df429
patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents:
20138
diff
changeset
|
2301 semsg(_(e_unknownfunc), namebuf); |
19330
9c8b803fe598
patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents:
19328
diff
changeset
|
2302 |
9c8b803fe598
patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents:
19328
diff
changeset
|
2303 theend: |
9c8b803fe598
patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents:
19328
diff
changeset
|
2304 vim_free(tofree); |
9c8b803fe598
patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents:
19328
diff
changeset
|
2305 return res; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2306 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2307 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2308 // 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
|
2309 #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
|
2310 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2311 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2312 * 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
|
2313 * does not recognize magic braces. |
19583
ba35daca6553
patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents:
19579
diff
changeset
|
2314 * When "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
|
2315 * 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
|
2316 * valid name. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2317 */ |
19583
ba35daca6553
patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents:
19579
diff
changeset
|
2318 static char_u * |
ba35daca6553
patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents:
19579
diff
changeset
|
2319 to_name_end(char_u *arg, int namespace) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2320 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2321 char_u *p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2322 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2323 // 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
|
2324 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
|
2325 return arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2326 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2327 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
|
2328 // 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
|
2329 // 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
|
2330 if (*p == ':' && (p != arg + 1 |
19583
ba35daca6553
patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents:
19579
diff
changeset
|
2331 || !namespace |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2332 || 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
|
2333 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2334 return p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2335 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2336 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2337 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2338 * 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
|
2339 * 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
|
2340 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2341 char_u * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2342 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
|
2343 { |
19583
ba35daca6553
patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents:
19579
diff
changeset
|
2344 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
|
2345 typval_T rettv; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2346 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2347 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
|
2348 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2349 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2350 // 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
|
2351 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
|
2352 p = arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2353 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2354 else if (p == arg && *arg == '#' && arg[1] == '{') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2355 { |
19822
fc3cdc819d80
patch 8.2.0467: Vim9: some errors are not tested
Bram Moolenaar <Bram@vim.org>
parents:
19818
diff
changeset
|
2356 // Can be "#{a: 1}->Func()". |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2357 ++p; |
21034
2f8b0812819f
patch 8.2.1068: Vim9: no line break allowed inside a dict
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
2358 if (eval_dict(&p, &rettv, NULL, TRUE) == FAIL) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2359 p = arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2360 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2361 else 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
|
2362 { |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
2363 int ret = get_lambda_tv(&p, &rettv, NULL); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2364 |
19822
fc3cdc819d80
patch 8.2.0467: Vim9: some errors are not tested
Bram Moolenaar <Bram@vim.org>
parents:
19818
diff
changeset
|
2365 // Can be "{x -> ret}()". |
fc3cdc819d80
patch 8.2.0467: Vim9: some errors are not tested
Bram Moolenaar <Bram@vim.org>
parents:
19818
diff
changeset
|
2366 // Can be "{'a': 1}->Func()". |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2367 if (ret == NOTDONE) |
21034
2f8b0812819f
patch 8.2.1068: Vim9: no line break allowed inside a dict
Bram Moolenaar <Bram@vim.org>
parents:
21028
diff
changeset
|
2368 ret = eval_dict(&p, &rettv, NULL, FALSE); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2369 if (ret != OK) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2370 p = arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2371 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2372 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2373 return p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2374 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2375 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2376 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2377 * 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
|
2378 * "*arg" points to the '['. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2379 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2380 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2381 compile_list(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
|
2382 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2383 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
|
2384 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
|
2385 int count = 0; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2386 |
19999
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
2387 for (;;) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2388 { |
20955
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
2389 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
|
2390 { |
20955
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
2391 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
|
2392 return FAIL; |
19999
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
2393 } |
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
2394 if (*p == ']') |
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
2395 { |
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
2396 ++p; |
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
2397 // Allow for following comment, after at least one space. |
21353
fb8c8fcb7b60
patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents:
21345
diff
changeset
|
2398 if (VIM_ISWHITE(*p) && *skipwhite(p) == '#') |
19999
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
2399 p += STRLEN(p); |
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
2400 break; |
19830
6500dcaf8e1a
patch 8.2.0471: missing change to compile_list()
Bram Moolenaar <Bram@vim.org>
parents:
19822
diff
changeset
|
2401 } |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2402 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
|
2403 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2404 ++count; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2405 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
|
2406 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2407 ++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
|
2408 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
|
2409 { |
bcd08812cde3
patch 8.2.1159: Vim9: no error for missing space after a comma
Bram Moolenaar <Bram@vim.org>
parents:
21210
diff
changeset
|
2410 semsg(_(e_white_after), ","); |
bcd08812cde3
patch 8.2.1159: Vim9: no error for missing space after a comma
Bram Moolenaar <Bram@vim.org>
parents:
21210
diff
changeset
|
2411 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
|
2412 } |
bcd08812cde3
patch 8.2.1159: Vim9: no error for missing space after a comma
Bram Moolenaar <Bram@vim.org>
parents:
21210
diff
changeset
|
2413 } |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
2414 whitep = p; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2415 p = skipwhite(p); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2416 } |
19999
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
2417 *arg = p; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2418 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2419 generate_NEWLIST(cctx, count); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2420 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2421 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2422 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2423 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2424 * parse a lambda: {arg, arg -> expr} |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2425 * "*arg" points to the '{'. |
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 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2428 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
|
2429 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2430 typval_T rettv; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2431 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
|
2432 evalarg_T evalarg; |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21202
diff
changeset
|
2433 |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21202
diff
changeset
|
2434 CLEAR_FIELD(evalarg); |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21202
diff
changeset
|
2435 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
|
2436 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
|
2437 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2438 // Get the funcref in "rettv". |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21202
diff
changeset
|
2439 if (get_lambda_tv(arg, &rettv, &evalarg) != OK) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2440 return FAIL; |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
2441 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2442 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
|
2443 ++ufunc->uf_refcount; |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
2444 clear_tv(&rettv); |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
2445 ga_init2(&ufunc->uf_type_list, sizeof(type_T *), 10); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2446 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2447 // The function will have one line: "return {expr}". |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2448 // Compile it into instructions. |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
2449 compile_def_function(ufunc, TRUE, cctx); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2450 |
21220
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21218
diff
changeset
|
2451 clear_evalarg(&evalarg, NULL); |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21218
diff
changeset
|
2452 |
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
|
2453 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
|
2454 { |
4e4fd845553d
patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents:
21691
diff
changeset
|
2455 // 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
|
2456 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
|
2457 |
4e4fd845553d
patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents:
21691
diff
changeset
|
2458 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
|
2459 } |
21353
fb8c8fcb7b60
patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents:
21345
diff
changeset
|
2460 |
fb8c8fcb7b60
patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents:
21345
diff
changeset
|
2461 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
|
2462 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2463 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2464 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2465 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2466 * Compile a lamda call: expr->{lambda}(args) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2467 * "arg" points to the "{". |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2468 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2469 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2470 compile_lambda_call(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
|
2471 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2472 ufunc_T *ufunc; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2473 typval_T rettv; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2474 int argcount = 1; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2475 int ret = FAIL; |
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 // Get the funcref in "rettv". |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21034
diff
changeset
|
2478 if (get_lambda_tv(arg, &rettv, &EVALARG_EVALUATE) == FAIL) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2479 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2480 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2481 if (**arg != '(') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2482 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2483 if (*skipwhite(*arg) == '(') |
19760
9daed26b788b
patch 8.2.0436: no warnings for incorrect printf arguments
Bram Moolenaar <Bram@vim.org>
parents:
19726
diff
changeset
|
2484 emsg(_(e_nowhitespace)); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2485 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2486 semsg(_(e_missing_paren), "lambda"); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2487 clear_tv(&rettv); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2488 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2489 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2490 |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
2491 ufunc = rettv.vval.v_partial->pt_func; |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
2492 ++ufunc->uf_refcount; |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
2493 clear_tv(&rettv); |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
2494 ga_init2(&ufunc->uf_type_list, sizeof(type_T *), 10); |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
2495 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2496 // The function will have one line: "return {expr}". |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2497 // Compile it into instructions. |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
2498 compile_def_function(ufunc, TRUE, cctx); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2499 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2500 // compile the arguments |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2501 *arg = skipwhite(*arg + 1); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2502 if (compile_arguments(arg, cctx, &argcount) == OK) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2503 // call the compiled function |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2504 ret = generate_CALL(cctx, ufunc, argcount); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2505 |
21353
fb8c8fcb7b60
patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents:
21345
diff
changeset
|
2506 if (ret == FAIL) |
fb8c8fcb7b60
patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents:
21345
diff
changeset
|
2507 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
|
2508 return ret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2509 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2510 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2511 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2512 * parse a dict: {'key': val} or #{key: val} |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2513 * "*arg" points to the '{'. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2514 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2515 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2516 compile_dict(char_u **arg, cctx_T *cctx, int literal) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2517 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2518 garray_T *instr = &cctx->ctx_instr; |
21301
60011b87aae1
patch 8.2.1201: Vim9: crash when passing number as dict key
Bram Moolenaar <Bram@vim.org>
parents:
21281
diff
changeset
|
2519 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
|
2520 int count = 0; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2521 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
|
2522 dictitem_T *item; |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
2523 char_u *whitep = *arg; |
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
2524 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
|
2525 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2526 if (d == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2527 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2528 *arg = skipwhite(*arg + 1); |
19999
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
2529 for (;;) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2530 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2531 char_u *key = NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2532 |
20955
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
2533 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
|
2534 { |
20955
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
2535 *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
|
2536 goto failret; |
19999
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
2537 } |
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
2538 |
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
2539 if (**arg == '}') |
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
2540 break; |
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
2541 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2542 if (literal) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2543 { |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
2544 char_u *end = to_name_end(*arg, !literal); |
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
2545 |
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
2546 if (end == *arg) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2547 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2548 semsg(_("E1014: Invalid key: %s"), *arg); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2549 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2550 } |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
2551 key = vim_strnsave(*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
|
2552 if (generate_PUSHS(cctx, key) == FAIL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2553 return FAIL; |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
2554 *arg = end; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2555 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2556 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2557 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2558 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2559 |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2560 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
|
2561 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2562 isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2563 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
|
2564 key = isn->isn_arg.string; |
21301
60011b87aae1
patch 8.2.1201: Vim9: crash when passing number as dict key
Bram Moolenaar <Bram@vim.org>
parents:
21281
diff
changeset
|
2565 else |
60011b87aae1
patch 8.2.1201: Vim9: crash when passing number as dict key
Bram Moolenaar <Bram@vim.org>
parents:
21281
diff
changeset
|
2566 { |
60011b87aae1
patch 8.2.1201: Vim9: crash when passing number as dict key
Bram Moolenaar <Bram@vim.org>
parents:
21281
diff
changeset
|
2567 type_T *keytype = ((type_T **)stack->ga_data) |
60011b87aae1
patch 8.2.1201: Vim9: crash when passing number as dict key
Bram Moolenaar <Bram@vim.org>
parents:
21281
diff
changeset
|
2568 [stack->ga_len - 1]; |
60011b87aae1
patch 8.2.1201: Vim9: crash when passing number as dict key
Bram Moolenaar <Bram@vim.org>
parents:
21281
diff
changeset
|
2569 if (need_type(keytype, &t_string, -1, cctx, FALSE) == FAIL) |
60011b87aae1
patch 8.2.1201: Vim9: crash when passing number as dict key
Bram Moolenaar <Bram@vim.org>
parents:
21281
diff
changeset
|
2570 return FAIL; |
60011b87aae1
patch 8.2.1201: Vim9: crash when passing number as dict key
Bram Moolenaar <Bram@vim.org>
parents:
21281
diff
changeset
|
2571 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2572 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2573 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2574 // 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
|
2575 if (key != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2576 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2577 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
|
2578 if (item != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2579 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2580 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
|
2581 goto failret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2582 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2583 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
|
2584 if (item != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2585 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2586 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
|
2587 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
|
2588 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
|
2589 dictitem_free(item); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2590 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2591 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2592 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2593 *arg = skipwhite(*arg); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2594 if (**arg != ':') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2595 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2596 semsg(_(e_missing_dict_colon), *arg); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2597 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2598 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2599 |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
2600 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
|
2601 *arg = skipwhite(*arg + 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
|
2602 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
|
2603 { |
20955
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
2604 *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
|
2605 goto failret; |
19999
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
2606 } |
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
2607 |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
2608 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
|
2609 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2610 ++count; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2611 |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
2612 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
|
2613 *arg = 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
|
2614 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
|
2615 { |
20955
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
2616 *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
|
2617 goto failret; |
19999
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
2618 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2619 if (**arg == '}') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2620 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2621 if (**arg != ',') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2622 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2623 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
|
2624 goto failret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2625 } |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
2626 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
|
2627 *arg = skipwhite(*arg + 1); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2628 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2629 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2630 *arg = *arg + 1; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2631 |
19999
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
2632 // 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
|
2633 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
|
2634 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
|
2635 *arg += STRLEN(*arg); |
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
2636 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2637 dict_unref(d); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2638 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
|
2639 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2640 failret: |
19999
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
2641 if (*arg == NULL) |
844c7646f61b
patch 8.2.0555: Vim9: line continuation is not always needed
Bram Moolenaar <Bram@vim.org>
parents:
19993
diff
changeset
|
2642 semsg(_(e_missing_dict_end), _("[end of lines]")); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2643 dict_unref(d); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2644 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2645 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2646 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2647 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2648 * Compile "&option". |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2649 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2650 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2651 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
|
2652 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2653 typval_T rettv; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2654 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
|
2655 int ret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2656 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2657 // 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
|
2658 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
|
2659 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
|
2660 if (ret == OK) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2661 { |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21116
diff
changeset
|
2662 // include the '&' in the name, eval_option() expects it. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2663 char_u *name = vim_strnsave(start, *arg - start); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2664 type_T *type = rettv.v_type == VAR_NUMBER ? &t_number : &t_string; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2665 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2666 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
|
2667 vim_free(name); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2668 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2669 clear_tv(&rettv); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2670 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2671 return ret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2672 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2673 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2674 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2675 * Compile "$VAR". |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2676 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2677 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2678 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
|
2679 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2680 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
|
2681 int len; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2682 int ret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2683 char_u *name; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2684 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2685 ++*arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2686 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
|
2687 if (len == 0) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2688 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2689 semsg(_(e_syntax_at), start - 1); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2690 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2691 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2692 |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21116
diff
changeset
|
2693 // 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
|
2694 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
|
2695 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
|
2696 vim_free(name); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2697 return ret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2698 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2699 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2700 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2701 * Compile "@r". |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2702 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2703 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2704 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
|
2705 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2706 int ret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2707 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2708 ++*arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2709 if (**arg == NUL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2710 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2711 semsg(_(e_syntax_at), *arg - 1); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2712 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2713 } |
21612
c495d3e30f4b
patch 8.2.1356: Vim9: cannot get the percent register
Bram Moolenaar <Bram@vim.org>
parents:
21610
diff
changeset
|
2714 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
|
2715 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2716 emsg_invreg(**arg); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2717 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2718 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2719 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
|
2720 ++*arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2721 return ret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2722 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2723 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2724 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2725 * 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
|
2726 * 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
|
2727 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2728 static int |
21739
caf0286cf02b
patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents:
21717
diff
changeset
|
2729 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
|
2730 { |
caf0286cf02b
patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents:
21717
diff
changeset
|
2731 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
|
2732 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2733 // 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
|
2734 while (p > start) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2735 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2736 --p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2737 if (*p == '-' || *p == '+') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2738 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2739 // 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
|
2740 #ifdef FEAT_FLOAT |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2741 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
|
2742 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2743 if (*p == '-') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2744 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
|
2745 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2746 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2747 #endif |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2748 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2749 varnumber_T val; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2750 int error = FALSE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2751 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2752 // 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
|
2753 // here |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2754 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
|
2755 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2756 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
|
2757 clear_tv(rettv); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2758 if (error) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2759 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2760 if (*p == '-') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2761 val = -val; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2762 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
|
2763 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
|
2764 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2765 } |
21739
caf0286cf02b
patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents:
21717
diff
changeset
|
2766 else if (numeric_only) |
caf0286cf02b
patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents:
21717
diff
changeset
|
2767 { |
caf0286cf02b
patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents:
21717
diff
changeset
|
2768 ++p; |
caf0286cf02b
patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents:
21717
diff
changeset
|
2769 break; |
caf0286cf02b
patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents:
21717
diff
changeset
|
2770 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2771 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2772 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2773 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
|
2774 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2775 // '!' 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
|
2776 clear_tv(rettv); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2777 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
|
2778 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
|
2779 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2780 } |
21739
caf0286cf02b
patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents:
21717
diff
changeset
|
2781 *end = p; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2782 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2783 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2784 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2785 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2786 * 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
|
2787 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2788 static void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2789 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
|
2790 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2791 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
|
2792 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2793 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
|
2794 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
|
2795 *arg += 6; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2796 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2797 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
|
2798 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2799 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
|
2800 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
|
2801 *arg += 7; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2802 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2803 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
|
2804 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2805 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
|
2806 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
|
2807 *arg += 6; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2808 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2809 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
|
2810 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2811 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
|
2812 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
|
2813 *arg += 6; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2814 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2815 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2816 |
21546
4d3e983313dc
patch 8.2.1323: Vim9: invalid operators only rejected in :def function
Bram Moolenaar <Bram@vim.org>
parents:
21540
diff
changeset
|
2817 exptype_T |
20305
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2818 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
|
2819 { |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2820 exptype_T type = EXPR_UNKNOWN; |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2821 int i; |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2822 |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2823 switch (p[0]) |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2824 { |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2825 case '=': if (p[1] == '=') |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2826 type = EXPR_EQUAL; |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2827 else if (p[1] == '~') |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2828 type = EXPR_MATCH; |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2829 break; |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2830 case '!': if (p[1] == '=') |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2831 type = EXPR_NEQUAL; |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2832 else if (p[1] == '~') |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2833 type = EXPR_NOMATCH; |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2834 break; |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2835 case '>': if (p[1] != '=') |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2836 { |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2837 type = EXPR_GREATER; |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2838 *len = 1; |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2839 } |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2840 else |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2841 type = EXPR_GEQUAL; |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2842 break; |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2843 case '<': if (p[1] != '=') |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2844 { |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2845 type = EXPR_SMALLER; |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2846 *len = 1; |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2847 } |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2848 else |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2849 type = EXPR_SEQUAL; |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2850 break; |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2851 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
|
2852 { |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2853 // "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
|
2854 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
|
2855 *len = 5; |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2856 i = p[*len]; |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2857 if (!isalnum(i) && i != '_') |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2858 { |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2859 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
|
2860 *type_is = TRUE; |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2861 } |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2862 } |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2863 break; |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2864 } |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2865 return type; |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2866 } |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2867 |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
2868 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2869 * 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
|
2870 * 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
|
2871 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2872 static int |
21739
caf0286cf02b
patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents:
21717
diff
changeset
|
2873 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
|
2874 { |
caf0286cf02b
patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents:
21717
diff
changeset
|
2875 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
|
2876 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2877 // 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
|
2878 while (p > start) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2879 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2880 --p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2881 if (*p == '-' || *p == '+') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2882 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2883 int negate = *p == '-'; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2884 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2885 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2886 // TODO: check type |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2887 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
|
2888 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2889 --p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2890 if (*p == '-') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2891 negate = !negate; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2892 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2893 // 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
|
2894 if (negate) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2895 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
|
2896 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2897 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
|
2898 if (isn == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2899 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2900 } |
21739
caf0286cf02b
patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents:
21717
diff
changeset
|
2901 else if (numeric_only) |
caf0286cf02b
patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents:
21717
diff
changeset
|
2902 { |
caf0286cf02b
patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents:
21717
diff
changeset
|
2903 ++p; |
caf0286cf02b
patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents:
21717
diff
changeset
|
2904 break; |
caf0286cf02b
patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents:
21717
diff
changeset
|
2905 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2906 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2907 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2908 int invert = TRUE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2909 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2910 while (p > start && p[-1] == '!') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2911 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2912 --p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2913 invert = !invert; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2914 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2915 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
|
2916 return FAIL; |
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 } |
21739
caf0286cf02b
patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents:
21717
diff
changeset
|
2919 *end = p; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2920 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2921 } |
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 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2924 * 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
|
2925 * 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
|
2926 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2927 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2928 compile_subscript( |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2929 char_u **arg, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2930 cctx_T *cctx, |
21739
caf0286cf02b
patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents:
21717
diff
changeset
|
2931 char_u *start_leader, |
caf0286cf02b
patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents:
21717
diff
changeset
|
2932 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
|
2933 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
|
2934 { |
21739
caf0286cf02b
patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents:
21717
diff
changeset
|
2935 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
|
2936 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2937 for (;;) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2938 { |
20955
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
2939 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
|
2940 |
21353
fb8c8fcb7b60
patch 8.2.1227: Vim9: allowing both quoted and # comments is confusing
Bram Moolenaar <Bram@vim.org>
parents:
21345
diff
changeset
|
2941 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
|
2942 { |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21202
diff
changeset
|
2943 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
|
2944 |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
2945 // 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
|
2946 // 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
|
2947 // 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
|
2948 if (next != NULL && |
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
2949 ((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
|
2950 && (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
|
2951 || (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
|
2952 { |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
2953 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
|
2954 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
|
2955 return FAIL; |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21202
diff
changeset
|
2956 *arg = next; |
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21202
diff
changeset
|
2957 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
|
2958 } |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
2959 } |
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
2960 |
21485
afc8cc1a291f
patch 8.2.1293: Vim9: error when using vim9script in TextYankPost
Bram Moolenaar <Bram@vim.org>
parents:
21473
diff
changeset
|
2961 // Do not skip over white space to find the "(", "exeucte 'x' ()" is |
afc8cc1a291f
patch 8.2.1293: Vim9: error when using vim9script in TextYankPost
Bram Moolenaar <Bram@vim.org>
parents:
21473
diff
changeset
|
2962 // 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
|
2963 if (**arg == '(') |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2964 { |
20203
5a397db2c1ed
patch 8.2.0657: Vim9: no check if called variable is a FuncRef
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
2965 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
|
2966 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
|
2967 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
|
2968 |
20324
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
2969 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
|
2970 return FAIL; |
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
2971 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2972 // 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
|
2973 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
|
2974 |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21202
diff
changeset
|
2975 *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
|
2976 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
|
2977 return FAIL; |
21739
caf0286cf02b
patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents:
21717
diff
changeset
|
2978 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
|
2979 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2980 } |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21202
diff
changeset
|
2981 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
|
2982 { |
21465
b5d4ab124782
patch 8.2.1283: Vim9: error for misplaced -> lacks argument
Bram Moolenaar <Bram@vim.org>
parents:
21463
diff
changeset
|
2983 char_u *pstart = p; |
b5d4ab124782
patch 8.2.1283: Vim9: error for misplaced -> lacks argument
Bram Moolenaar <Bram@vim.org>
parents:
21463
diff
changeset
|
2984 |
20324
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
2985 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
|
2986 return FAIL; |
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
2987 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2988 // something->method() |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2989 // 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
|
2990 // -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
|
2991 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
|
2992 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2993 |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21202
diff
changeset
|
2994 p += 2; |
20949
62912ad41aff
patch 8.2.1026: Vim9: cannot break the line after "->"
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
2995 *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
|
2996 // No line break supported right after "->". |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2997 if (**arg == '{') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2998 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2999 // lambda call: list->{lambda} |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3000 if (compile_lambda_call(arg, cctx) == FAIL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3001 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3002 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3003 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3004 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3005 // 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
|
3006 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
|
3007 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
|
3008 { |
21465
b5d4ab124782
patch 8.2.1283: Vim9: error for misplaced -> lacks argument
Bram Moolenaar <Bram@vim.org>
parents:
21463
diff
changeset
|
3009 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
|
3010 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
|
3011 } |
19848
36d629aa3d6e
patch 8.2.0480: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
19830
diff
changeset
|
3012 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
|
3013 p += 2; |
21650
79a8d723a3d2
patch 8.2.1375: Vim9: method name with digit not accepted
Bram Moolenaar <Bram@vim.org>
parents:
21648
diff
changeset
|
3014 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
|
3015 ; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3016 if (*p != '(') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3017 { |
19848
36d629aa3d6e
patch 8.2.0480: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
19830
diff
changeset
|
3018 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
|
3019 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3020 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3021 // 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
|
3022 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
|
3023 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3024 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3025 } |
21562
55aa283a0e5e
patch 8.2.1331: Vim9: :echo with two lists doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3026 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
|
3027 { |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
3028 garray_T *stack = &cctx->ctx_type_stack; |
19423
f3e8e74cb747
patch 8.2.0269: Vim9: operator after list index does not work
Bram Moolenaar <Bram@vim.org>
parents:
19411
diff
changeset
|
3029 type_T **typep; |
21387
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3030 vartype_T vtype; |
19423
f3e8e74cb747
patch 8.2.0269: Vim9: operator after list index does not work
Bram Moolenaar <Bram@vim.org>
parents:
19411
diff
changeset
|
3031 |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
3032 // 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
|
3033 // 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
|
3034 // string index: text[123] |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
3035 // TODO: blob index |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
3036 // 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
|
3037 // 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
|
3038 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
|
3039 return FAIL; |
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3040 |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21202
diff
changeset
|
3041 ++p; |
20949
62912ad41aff
patch 8.2.1026: Vim9: cannot break the line after "->"
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
3042 *arg = skipwhite(p); |
21248
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
3043 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
|
3044 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
|
3045 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
|
3046 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3047 |
21248
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
3048 if (may_get_next_line_error(p, arg, cctx) == FAIL) |
4edc60c9c0aa
patch 8.2.1175: Vim9: cannot split a line before ".member"
Bram Moolenaar <Bram@vim.org>
parents:
21232
diff
changeset
|
3049 return FAIL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3050 if (**arg != ']') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3051 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3052 emsg(_(e_missbrac)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3053 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3054 } |
19342
8ff84bc1c89b
patch 8.2.0229: compare instructions not tested
Bram Moolenaar <Bram@vim.org>
parents:
19336
diff
changeset
|
3055 *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
|
3056 |
21387
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3057 // We can index a list and a dict. If we don't know the type |
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3058 // we can use the index value type. |
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3059 // TODO: If we don't know use an instruction to figure it out at |
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3060 // runtime. |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
3061 typep = ((type_T **)stack->ga_data) + stack->ga_len - 2; |
21387
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3062 vtype = (*typep)->tt_type; |
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3063 if (*typep == &t_any) |
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3064 { |
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3065 type_T *valtype = ((type_T **)stack->ga_data) |
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3066 [stack->ga_len - 1]; |
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3067 if (valtype == &t_string) |
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3068 vtype = VAR_DICT; |
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3069 } |
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3070 if (vtype == VAR_DICT) |
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3071 { |
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3072 if ((*typep)->tt_type == VAR_DICT) |
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3073 *typep = (*typep)->tt_member; |
21411
e1aeb986712f
patch 8.2.1256: Vim9: type wrong after getting dict item in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21399
diff
changeset
|
3074 else |
e1aeb986712f
patch 8.2.1256: Vim9: type wrong after getting dict item in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21399
diff
changeset
|
3075 { |
e1aeb986712f
patch 8.2.1256: Vim9: type wrong after getting dict item in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21399
diff
changeset
|
3076 if (need_type(*typep, &t_dict_any, -2, cctx, FALSE) == FAIL) |
e1aeb986712f
patch 8.2.1256: Vim9: type wrong after getting dict item in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21399
diff
changeset
|
3077 return FAIL; |
e1aeb986712f
patch 8.2.1256: Vim9: type wrong after getting dict item in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21399
diff
changeset
|
3078 *typep = &t_any; |
e1aeb986712f
patch 8.2.1256: Vim9: type wrong after getting dict item in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21399
diff
changeset
|
3079 } |
21387
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3080 if (may_generate_2STRING(-1, cctx) == FAIL) |
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3081 return FAIL; |
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3082 if (generate_instr_drop(cctx, ISN_MEMBER, 1) == FAIL) |
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3083 return FAIL; |
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3084 } |
21393
320581a133d9
patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents:
21391
diff
changeset
|
3085 else if (vtype == VAR_STRING) |
320581a133d9
patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents:
21391
diff
changeset
|
3086 { |
320581a133d9
patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents:
21391
diff
changeset
|
3087 *typep = &t_number; |
320581a133d9
patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents:
21391
diff
changeset
|
3088 if (generate_instr_drop(cctx, ISN_STRINDEX, 1) == FAIL) |
320581a133d9
patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents:
21391
diff
changeset
|
3089 return FAIL; |
320581a133d9
patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents:
21391
diff
changeset
|
3090 } |
21387
8d58cbb07a12
patch 8.2.1244: Vim9: in lambda index assumes a list
Bram Moolenaar <Bram@vim.org>
parents:
21385
diff
changeset
|
3091 else if (vtype == VAR_LIST || *typep == &t_any) |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
3092 { |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
3093 if ((*typep)->tt_type == VAR_LIST) |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
3094 *typep = (*typep)->tt_member; |
21393
320581a133d9
patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents:
21391
diff
changeset
|
3095 if (generate_instr_drop(cctx, ISN_LISTINDEX, 1) == FAIL) |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
3096 return FAIL; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
3097 } |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
3098 else |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
3099 { |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
3100 emsg(_(e_listdictblobreq)); |
19423
f3e8e74cb747
patch 8.2.0269: Vim9: operator after list index does not work
Bram Moolenaar <Bram@vim.org>
parents:
19411
diff
changeset
|
3101 return FAIL; |
f3e8e74cb747
patch 8.2.0269: Vim9: operator after list index does not work
Bram Moolenaar <Bram@vim.org>
parents:
19411
diff
changeset
|
3102 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3103 } |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21202
diff
changeset
|
3104 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
|
3105 { |
20324
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3106 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
|
3107 return FAIL; |
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3108 |
21208
09377fd59b2e
patch 8.2.1155: Vim9: cannot handle line break inside lambda
Bram Moolenaar <Bram@vim.org>
parents:
21202
diff
changeset
|
3109 *arg = p + 1; |
20949
62912ad41aff
patch 8.2.1026: Vim9: cannot break the line after "->"
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
3110 if (may_get_next_line(*arg, arg, cctx) == FAIL) |
62912ad41aff
patch 8.2.1026: Vim9: cannot break the line after "->"
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
3111 return FAIL; |
62912ad41aff
patch 8.2.1026: Vim9: cannot break the line after "->"
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
3112 // dictionary member: dict.name |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3113 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
|
3114 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
|
3115 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
|
3116 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
|
3117 if (p == *arg) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3118 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3119 semsg(_(e_syntax_at), *arg); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3120 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3121 } |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
3122 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
|
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 *arg = p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3125 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3126 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3127 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3128 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3129 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3130 // 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
|
3131 // 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
|
3132 // 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
|
3133 // 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
|
3134 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3135 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3136 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3137 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3138 /* |
20318
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3139 * 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
|
3140 * "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
|
3141 * |
20324
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3142 * If the value is a constant "ppconst->pp_ret" will be set. |
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3143 * 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
|
3144 * |
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3145 * 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
|
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 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3149 * number number constant |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3150 * 0zFFFFFFFF Blob constant |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3151 * "string" string constant |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3152 * '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
|
3153 * &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
|
3154 * @r register contents |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3155 * identifier variable value |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3156 * function() function call |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3157 * $VAR environment variable |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3158 * (expression) nested expression |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3159 * [expr, expr] List |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3160 * {key: val, key: val} Dictionary |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3161 * #{key: val, key: val} Dictionary with literal keys |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3162 * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3163 * Also handle: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3164 * ! 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
|
3165 * - 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
|
3166 * + 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
|
3167 * 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
|
3168 * 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
|
3169 * 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
|
3170 * 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
|
3171 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3172 static int |
20318
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3173 compile_expr7( |
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3174 char_u **arg, |
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3175 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
|
3176 ppconst_T *ppconst) |
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3177 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3178 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
|
3179 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
|
3180 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
|
3181 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
|
3182 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3183 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3184 * 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
|
3185 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3186 start_leader = *arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3187 while (**arg == '!' || **arg == '-' || **arg == '+') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3188 *arg = skipwhite(*arg + 1); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3189 end_leader = *arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3190 |
20324
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3191 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
|
3192 switch (**arg) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3193 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3194 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3195 * Number constant. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3196 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3197 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
|
3198 case '1': |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3199 case '2': |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3200 case '3': |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3201 case '4': |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3202 case '5': |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3203 case '6': |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3204 case '7': |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3205 case '8': |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3206 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
|
3207 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
|
3208 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
|
3209 // 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
|
3210 // 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
|
3211 // '!'. |
a7e0091a4669
patch 8.2.1421: Vim9: handling "+" and "-" before number differs from script
Bram Moolenaar <Bram@vim.org>
parents:
21739
diff
changeset
|
3212 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
|
3213 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
|
3214 { |
a7e0091a4669
patch 8.2.1421: Vim9: handling "+" and "-" before number differs from script
Bram Moolenaar <Bram@vim.org>
parents:
21739
diff
changeset
|
3215 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
|
3216 return FAIL; |
a7e0091a4669
patch 8.2.1421: Vim9: handling "+" and "-" before number differs from script
Bram Moolenaar <Bram@vim.org>
parents:
21739
diff
changeset
|
3217 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3218 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3219 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3220 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3221 * String constant: "string". |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3222 */ |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21116
diff
changeset
|
3223 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
|
3224 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3225 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3226 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3227 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3228 * 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
|
3229 */ |
21120
4d844a65183d
patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents:
21116
diff
changeset
|
3230 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
|
3231 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3232 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3233 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3234 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3235 * Constant Vim variable. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3236 */ |
20324
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3237 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
|
3238 ret = NOTDONE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3239 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3240 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3241 /* |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3242 * "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
|
3243 */ |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3244 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
|
3245 && !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
|
3246 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3247 *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
|
3248 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
|
3249 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
|
3250 } |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3251 else |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3252 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
|
3253 break; |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3254 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3255 /* |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3256 * "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
|
3257 */ |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3258 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
|
3259 && !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
|
3260 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3261 *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
|
3262 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
|
3263 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
|
3264 } |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3265 else |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3266 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
|
3267 break; |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3268 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3269 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3270 * List: [expr, expr] |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3271 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3272 case '[': ret = compile_list(arg, cctx); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3273 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3274 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3275 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3276 * 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
|
3277 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3278 case '#': if ((*arg)[1] == '{') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3279 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3280 ++*arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3281 ret = compile_dict(arg, cctx, TRUE); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3282 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3283 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3284 ret = NOTDONE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3285 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3286 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3287 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3288 * Lambda: {arg, arg -> expr} |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3289 * 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
|
3290 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3291 case '{': { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3292 char_u *start = skipwhite(*arg + 1); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3293 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3294 // Find out what comes after the arguments. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3295 ret = get_function_args(&start, '-', NULL, |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20013
diff
changeset
|
3296 NULL, NULL, NULL, TRUE, NULL, NULL); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3297 if (ret != FAIL && *start == '>') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3298 ret = compile_lambda(arg, cctx); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3299 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3300 ret = compile_dict(arg, cctx, FALSE); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3301 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3302 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3303 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3304 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3305 * Option value: &name |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3306 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3307 case '&': ret = compile_get_option(arg, cctx); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3308 break; |
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 * Environment variable: $VAR. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3312 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3313 case '$': ret = compile_get_env(arg, cctx); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3314 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3315 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3316 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3317 * Register contents: @r. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3318 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3319 case '@': ret = compile_get_register(arg, cctx); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3320 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3321 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3322 * nested expression: (expression). |
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 case '(': *arg = skipwhite(*arg + 1); |
20336
2fd980fb9ab3
patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents:
20334
diff
changeset
|
3325 |
2fd980fb9ab3
patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents:
20334
diff
changeset
|
3326 // recursive! |
2fd980fb9ab3
patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents:
20334
diff
changeset
|
3327 if (ppconst->pp_used <= PPSIZE - 10) |
2fd980fb9ab3
patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents:
20334
diff
changeset
|
3328 { |
2fd980fb9ab3
patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents:
20334
diff
changeset
|
3329 ret = compile_expr1(arg, cctx, ppconst); |
2fd980fb9ab3
patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents:
20334
diff
changeset
|
3330 } |
2fd980fb9ab3
patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents:
20334
diff
changeset
|
3331 else |
2fd980fb9ab3
patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents:
20334
diff
changeset
|
3332 { |
2fd980fb9ab3
patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents:
20334
diff
changeset
|
3333 // Not enough space in ppconst, flush constants. |
2fd980fb9ab3
patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents:
20334
diff
changeset
|
3334 if (generate_ppconst(cctx, ppconst) == FAIL) |
2fd980fb9ab3
patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents:
20334
diff
changeset
|
3335 return FAIL; |
2fd980fb9ab3
patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents:
20334
diff
changeset
|
3336 ret = compile_expr0(arg, cctx); |
2fd980fb9ab3
patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents:
20334
diff
changeset
|
3337 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3338 *arg = skipwhite(*arg); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3339 if (**arg == ')') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3340 ++*arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3341 else if (ret == OK) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3342 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3343 emsg(_(e_missing_close)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3344 ret = FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3345 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3346 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3347 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3348 default: ret = NOTDONE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3349 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3350 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3351 if (ret == FAIL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3352 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3353 |
20336
2fd980fb9ab3
patch 8.2.0723: Vim9: nested constant expression not evaluated compile time
Bram Moolenaar <Bram@vim.org>
parents:
20334
diff
changeset
|
3354 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
|
3355 { |
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
|
3356 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
|
3357 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
|
3358 else |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3359 // 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
|
3360 // 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
|
3361 ++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
|
3362 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3363 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
|
3364 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3365 char_u *p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3366 int r; |
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 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
|
3369 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3370 semsg(_("E1015: Name expected: %s"), *arg); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3371 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3372 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3373 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3374 // "name" or "name()" |
19583
ba35daca6553
patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents:
19579
diff
changeset
|
3375 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
|
3376 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
|
3377 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3378 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
|
3379 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3380 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
|
3381 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3382 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
|
3383 return FAIL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3384 r = compile_load(arg, p, cctx, 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
|
3385 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3386 if (r == FAIL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3387 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3388 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3389 |
20322
a3e78893a90b
patch 8.2.0716: Vim9: another memory leak
Bram Moolenaar <Bram@vim.org>
parents:
20320
diff
changeset
|
3390 // Handle following "[]", ".member", etc. |
a3e78893a90b
patch 8.2.0716: Vim9: another memory leak
Bram Moolenaar <Bram@vim.org>
parents:
20320
diff
changeset
|
3391 // 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
|
3392 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
|
3393 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
|
3394 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
|
3395 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
|
3396 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3397 // 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
|
3398 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
|
3399 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
|
3400 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
|
3401 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
|
3402 } |
21739
caf0286cf02b
patch 8.2.1419: Vim9: not operator applied too early
Bram Moolenaar <Bram@vim.org>
parents:
21717
diff
changeset
|
3403 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
|
3404 return FAIL; |
20322
a3e78893a90b
patch 8.2.0716: Vim9: another memory leak
Bram Moolenaar <Bram@vim.org>
parents:
20320
diff
changeset
|
3405 return OK; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3406 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3407 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3408 /* |
21630
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21614
diff
changeset
|
3409 * 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
|
3410 */ |
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21614
diff
changeset
|
3411 void |
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21614
diff
changeset
|
3412 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
|
3413 { |
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21614
diff
changeset
|
3414 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
|
3415 |
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21614
diff
changeset
|
3416 vim_strncpy(buf, op, len); |
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21614
diff
changeset
|
3417 semsg(_(e_white_both), buf); |
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21614
diff
changeset
|
3418 } |
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21614
diff
changeset
|
3419 |
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21614
diff
changeset
|
3420 /* |
21717
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3421 * <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
|
3422 */ |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3423 static int |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3424 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
|
3425 { |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3426 type_T *want_type = NULL; |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3427 |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3428 // Recognize <type> |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3429 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
|
3430 { |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3431 int called_emsg_before = called_emsg; |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3432 |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3433 ++*arg; |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3434 want_type = parse_type(arg, cctx->ctx_type_list); |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3435 if (called_emsg != called_emsg_before) |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3436 return FAIL; |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3437 |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3438 if (**arg != '>') |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3439 { |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3440 if (*skipwhite(*arg) == '>') |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3441 semsg(_(e_no_white_before), ">"); |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3442 else |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3443 emsg(_("E1104: Missing >")); |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3444 return FAIL; |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3445 } |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3446 ++*arg; |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3447 if (may_get_next_line_error(*arg - 1, arg, cctx) == FAIL) |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3448 return FAIL; |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3449 } |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3450 |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3451 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
|
3452 return FAIL; |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3453 |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3454 if (want_type != NULL) |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3455 { |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3456 garray_T *stack = &cctx->ctx_type_stack; |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3457 type_T *actual = ((type_T **)stack->ga_data)[stack->ga_len - 1]; |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3458 |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3459 if (check_type(want_type, actual, FALSE) == FAIL) |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3460 { |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3461 generate_ppconst(cctx, ppconst); |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3462 if (need_type(actual, want_type, -1, cctx, FALSE) == FAIL) |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3463 return FAIL; |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3464 } |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3465 } |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3466 |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3467 return OK; |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3468 } |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3469 |
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3470 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3471 * * number multiplication |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3472 * / number division |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3473 * % number modulo |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3474 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3475 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
|
3476 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
|
3477 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3478 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
|
3479 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
|
3480 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
|
3481 |
20318
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3482 // get the first expression |
21717
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3483 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
|
3484 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3485 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3486 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3487 * 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
|
3488 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3489 for (;;) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3490 { |
20988
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
3491 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
|
3492 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
|
3493 break; |
20988
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
3494 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
|
3495 { |
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
3496 *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
|
3497 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
|
3498 } |
20318
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3499 |
20013
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
3500 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
|
3501 { |
21630
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21614
diff
changeset
|
3502 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
|
3503 return FAIL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3504 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3505 *arg = skipwhite(op + 1); |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
3506 if (may_get_next_line(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
|
3507 return FAIL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3508 |
20318
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3509 // get the second expression |
21717
ef3b31d510d2
patch 8.2.1408: Vim9: type casting not supported
Bram Moolenaar <Bram@vim.org>
parents:
21715
diff
changeset
|
3510 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
|
3511 return FAIL; |
20324
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3512 |
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3513 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
|
3514 && 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
|
3515 && 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
|
3516 { |
20324
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3517 typval_T *tv1 = &ppconst->pp_tv[ppconst_used]; |
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3518 typval_T *tv2 = &ppconst->pp_tv[ppconst_used + 1]; |
20318
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3519 varnumber_T res = 0; |
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3520 |
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3521 // 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
|
3522 switch (*op) |
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3523 { |
20324
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3524 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
|
3525 break; |
20324
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3526 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
|
3527 break; |
20324
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3528 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
|
3529 break; |
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3530 } |
20324
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3531 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
|
3532 --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
|
3533 } |
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3534 else |
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3535 { |
20324
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3536 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
|
3537 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
|
3538 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3539 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3540 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3541 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3542 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3543 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3544 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3545 * + number addition |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3546 * - number subtraction |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3547 * .. string concatenation |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3548 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3549 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
|
3550 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
|
3551 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3552 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
|
3553 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
|
3554 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
|
3555 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
|
3556 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3557 // 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
|
3558 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
|
3559 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3560 |
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 * 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
|
3563 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3564 for (;;) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3565 { |
20988
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
3566 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
|
3567 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
|
3568 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3569 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
|
3570 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
|
3571 { |
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
3572 *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
|
3573 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
|
3574 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3575 |
20013
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
3576 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
|
3577 { |
21630
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21614
diff
changeset
|
3578 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
|
3579 return FAIL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3580 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3581 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3582 *arg = skipwhite(op + oplen); |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
3583 if (may_get_next_line(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
|
3584 return FAIL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3585 |
20318
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3586 // 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
|
3587 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
|
3588 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
|
3589 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3590 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
|
3591 && (*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
|
3592 ? (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
|
3593 && 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
|
3594 : (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
|
3595 && 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
|
3596 { |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3597 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
|
3598 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
|
3599 |
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3600 // 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
|
3601 if (*op == '+') |
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3602 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
|
3603 else if (*op == '-') |
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3604 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
|
3605 else |
20318
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3606 { |
20324
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3607 // concatenate constant strings |
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3608 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
|
3609 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
|
3610 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
|
3611 |
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3612 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
|
3613 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
|
3614 { |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3615 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
|
3616 return FAIL; |
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3617 } |
23188ef99fc2
patch 8.2.0717: Vim9: postponed constant expressions does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20322
diff
changeset
|
3618 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
|
3619 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
|
3620 vim_free(s1); |
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3621 vim_free(s2); |
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3622 } |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3623 --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
|
3624 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3625 else |
20318
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3626 { |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3627 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
|
3628 if (*op == '.') |
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3629 { |
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3630 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
|
3631 || 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
|
3632 return FAIL; |
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3633 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
|
3634 } |
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3635 else |
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3636 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
|
3637 } |
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
diff
changeset
|
3638 } |
3cbcee39fc5c
patch 8.2.0714: Vim9: handling constant expression does not scale
Bram Moolenaar <Bram@vim.org>
parents:
20305
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 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3641 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3642 |
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 * expr5a == expr5b |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3645 * expr5a =~ expr5b |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3646 * expr5a != expr5b |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3647 * expr5a !~ expr5b |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3648 * expr5a > expr5b |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3649 * expr5a >= expr5b |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3650 * expr5a < expr5b |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3651 * expr5a <= expr5b |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3652 * expr5a is expr5b |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3653 * expr5a isnot expr5b |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3654 * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3655 * Produces instructions: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3656 * 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
|
3657 * 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
|
3658 * 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
|
3659 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3660 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
|
3661 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
|
3662 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3663 exptype_T type = EXPR_UNKNOWN; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3664 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
|
3665 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
|
3666 int len = 2; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3667 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
|
3668 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
|
3669 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3670 // 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
|
3671 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
|
3672 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3673 |
20988
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
3674 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
|
3675 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
|
3676 |
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 * 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
|
3679 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3680 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
|
3681 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3682 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
|
3683 |
20988
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
3684 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
|
3685 { |
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
3686 *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
|
3687 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
|
3688 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3689 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
|
3690 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3691 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
|
3692 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3693 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3694 // 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
|
3695 if (p[len] == '?') |
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 ic = TRUE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3698 ++len; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3699 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3700 // 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
|
3701 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
|
3702 ++len; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3703 // 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
|
3704 |
20013
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
3705 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
|
3706 { |
21630
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21614
diff
changeset
|
3707 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
|
3708 return FAIL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3709 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3710 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3711 // get the second variable |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3712 *arg = skipwhite(p + len); |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
3713 if (may_get_next_line(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
|
3714 return FAIL; |
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
3715 |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3716 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
|
3717 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3718 |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3719 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
|
3720 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3721 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
|
3722 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
|
3723 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
|
3724 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3725 // 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
|
3726 // 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
|
3727 // 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
|
3728 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
|
3729 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
|
3730 else |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3731 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3732 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
|
3733 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
|
3734 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
|
3735 ? 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
|
3736 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
|
3737 --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
|
3738 } |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3739 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
|
3740 } |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3741 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3742 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
|
3743 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
|
3744 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3745 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3746 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3747 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3748 |
20334
b774655968b4
patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents:
20332
diff
changeset
|
3749 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
|
3750 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3751 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3752 * Compile || or &&. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3753 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3754 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
|
3755 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
|
3756 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
|
3757 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
|
3758 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
|
3759 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
|
3760 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
|
3761 { |
20988
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
3762 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
|
3763 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
|
3764 int opchar = *op; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3765 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3766 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
|
3767 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3768 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
|
3769 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
|
3770 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3771 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3772 * 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
|
3773 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3774 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
|
3775 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
|
3776 { |
20988
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
3777 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
|
3778 { |
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
3779 *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
|
3780 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
|
3781 } |
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
3782 |
20013
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
3783 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
|
3784 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3785 semsg(_(e_white_both), op); |
20013
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
3786 return FAIL; |
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
3787 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3788 |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3789 // TODO: use ppconst if the value is a constant |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3790 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
|
3791 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3792 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
|
3793 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3794 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
|
3795 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3796 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3797 *(((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
|
3798 ++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
|
3799 generate_JUMP(cctx, opchar == '|' |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3800 ? JUMP_AND_KEEP_IF_TRUE : JUMP_AND_KEEP_IF_FALSE, 0); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3801 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3802 // eval the next expression |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3803 *arg = skipwhite(p + 2); |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
3804 if (may_get_next_line(p + 2, 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
|
3805 return FAIL; |
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
3806 |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3807 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
|
3808 : 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
|
3809 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3810 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
|
3811 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3812 } |
20988
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
3813 |
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
3814 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
|
3815 } |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3816 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
|
3817 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3818 // 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
|
3819 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
|
3820 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3821 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3822 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3823 --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
|
3824 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
|
3825 + *(((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
|
3826 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
|
3827 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3828 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
|
3829 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3830 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3831 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3832 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3833 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3834 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3835 * 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
|
3836 * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3837 * Produces instructions: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3838 * EVAL expr4a Push result of "expr4a" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3839 * JUMP_AND_KEEP_IF_FALSE end |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3840 * EVAL expr4b Push result of "expr4b" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3841 * JUMP_AND_KEEP_IF_FALSE end |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3842 * 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
|
3843 * end: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3844 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3845 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
|
3846 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
|
3847 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3848 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
|
3849 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3850 // 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
|
3851 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
|
3852 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3853 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3854 // || 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
|
3855 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
|
3856 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3857 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3858 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3859 * 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
|
3860 * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3861 * Produces instructions: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3862 * EVAL expr3a Push result of "expr3a" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3863 * JUMP_AND_KEEP_IF_TRUE end |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3864 * EVAL expr3b Push result of "expr3b" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3865 * JUMP_AND_KEEP_IF_TRUE end |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3866 * 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
|
3867 * end: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3868 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3869 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
|
3870 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
|
3871 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3872 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
|
3873 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3874 // 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
|
3875 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
|
3876 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3877 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3878 // || 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
|
3879 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
|
3880 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3881 |
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 * 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
|
3884 * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3885 * Produces instructions: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3886 * EVAL expr2 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
|
3887 * 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
|
3888 * EVAL expr1a |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3889 * JUMP_ALWAYS end |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3890 * alt: EVAL expr1b |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3891 * end: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3892 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3893 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
|
3894 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
|
3895 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3896 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
|
3897 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
|
3898 char_u *next; |
20305
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
3899 |
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
3900 // 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
|
3901 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
|
3902 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3903 |
20988
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
3904 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
|
3905 if (*p == '?') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3906 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3907 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
|
3908 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
|
3909 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
|
3910 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
|
3911 isn_T *isn; |
20966
0ee7de260208
patch 8.2.1034: compiler warning for uninitialized variables
Bram Moolenaar <Bram@vim.org>
parents:
20961
diff
changeset
|
3912 type_T *type1 = NULL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3913 type_T *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
|
3914 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
|
3915 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
|
3916 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
|
3917 |
20988
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
3918 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
|
3919 { |
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
3920 *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
|
3921 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
|
3922 } |
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
3923 |
20013
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
3924 if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[1])) |
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
3925 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3926 semsg(_(e_white_both), "?"); |
20013
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
3927 return FAIL; |
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
3928 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3929 |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3930 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
|
3931 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3932 // 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
|
3933 // 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
|
3934 has_const_expr = TRUE; |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3935 const_value = tv2bool(&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
|
3936 clear_tv(&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
|
3937 --ppconst->pp_used; |
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
|
3938 cctx->ctx_skip = save_skip == SKIP_YES || !const_value |
4eeda7139133
patch 8.2.1005: Vim9: using TRUE/FALSE/MAYBE for ctx_skip is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20899
diff
changeset
|
3939 ? SKIP_YES : 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
|
3940 } |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3941 else |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3942 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3943 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
|
3944 generate_JUMP(cctx, JUMP_IF_FALSE, 0); |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3945 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3946 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3947 // evaluate the second expression; any type is accepted |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3948 *arg = skipwhite(p + 1); |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
3949 if (may_get_next_line(p + 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
|
3950 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
|
3951 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
|
3952 return FAIL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3953 |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3954 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
|
3955 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3956 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
|
3957 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3958 // remember the type and drop it |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3959 --stack->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
|
3960 type1 = ((type_T **)stack->ga_data)[stack->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
|
3961 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3962 end_idx = 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
|
3963 generate_JUMP(cctx, JUMP_ALWAYS, 0); |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3964 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3965 // jump here from JUMP_IF_FALSE |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3966 isn = ((isn_T *)instr->ga_data) + alt_idx; |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3967 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
|
3968 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3969 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3970 // Check for the ":". |
20988
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
3971 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
|
3972 if (*p != ':') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3973 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3974 emsg(_(e_missing_colon)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3975 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3976 } |
20988
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
3977 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
|
3978 { |
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
3979 *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
|
3980 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
|
3981 } |
ae4b1d497a06
patch 8.2.1045: Vim9: line break before operator does not work
Bram Moolenaar <Bram@vim.org>
parents:
20982
diff
changeset
|
3982 |
20013
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
3983 if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[1])) |
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
3984 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3985 semsg(_(e_white_both), ":"); |
20013
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
3986 return FAIL; |
bf377a9ffccb
patch 8.2.0562: Vim9: cannot split an expression into multiple lines
Bram Moolenaar <Bram@vim.org>
parents:
20011
diff
changeset
|
3987 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3988 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3989 // evaluate the third 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
|
3990 if (has_const_expr) |
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
|
3991 cctx->ctx_skip = save_skip == SKIP_YES || const_value |
4eeda7139133
patch 8.2.1005: Vim9: using TRUE/FALSE/MAYBE for ctx_skip is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20899
diff
changeset
|
3992 ? SKIP_YES : SKIP_NOT; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3993 *arg = skipwhite(p + 1); |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20019
diff
changeset
|
3994 if (may_get_next_line(p + 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
|
3995 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
|
3996 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
|
3997 return FAIL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3998 |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
3999 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
|
4000 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
4001 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
|
4002 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
4003 // If the types differ, the result has a more generic type. |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
4004 type2 = ((type_T **)stack->ga_data)[stack->ga_len - 1]; |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
4005 common_type(type1, type2, &type2, cctx->ctx_type_list); |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
4006 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
4007 // jump here from JUMP_ALWAYS |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
4008 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
|
4009 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
|
4010 } |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
4011 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
4012 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
|
4013 } |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
4014 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
|
4015 } |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
4016 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
4017 /* |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
4018 * Toplevel expression. |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
4019 */ |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
4020 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
|
4021 compile_expr0(char_u **arg, 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
|
4022 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
4023 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
|
4024 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
4025 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
|
4026 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
|
4027 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
4028 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
|
4029 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
|
4030 } |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
4031 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
|
4032 return FAIL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4033 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4034 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4035 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4036 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4037 * compile "return [expr]" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4038 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4039 static char_u * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4040 compile_return(char_u *arg, int set_return_type, cctx_T *cctx) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4041 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4042 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
|
4043 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
|
4044 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
|
4045 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4046 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
|
4047 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4048 // 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
|
4049 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
|
4050 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4051 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4052 stack_type = ((type_T **)stack->ga_data)[stack->ga_len - 1]; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4053 if (set_return_type) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4054 cctx->ctx_ufunc->uf_ret_type = stack_type; |
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
|
4055 else |
1a393685e7ce
patch 8.2.1131: Vim9: error message for returning a value is not clear
Bram Moolenaar <Bram@vim.org>
parents:
21158
diff
changeset
|
4056 { |
1a393685e7ce
patch 8.2.1131: Vim9: error message for returning a value is not clear
Bram Moolenaar <Bram@vim.org>
parents:
21158
diff
changeset
|
4057 if (cctx->ctx_ufunc->uf_ret_type->tt_type == VAR_VOID |
1a393685e7ce
patch 8.2.1131: Vim9: error message for returning a value is not clear
Bram Moolenaar <Bram@vim.org>
parents:
21158
diff
changeset
|
4058 && stack_type->tt_type != VAR_VOID |
1a393685e7ce
patch 8.2.1131: Vim9: error message for returning a value is not clear
Bram Moolenaar <Bram@vim.org>
parents:
21158
diff
changeset
|
4059 && stack_type->tt_type != VAR_UNKNOWN) |
1a393685e7ce
patch 8.2.1131: Vim9: error message for returning a value is not clear
Bram Moolenaar <Bram@vim.org>
parents:
21158
diff
changeset
|
4060 { |
1a393685e7ce
patch 8.2.1131: Vim9: error message for returning a value is not clear
Bram Moolenaar <Bram@vim.org>
parents:
21158
diff
changeset
|
4061 emsg(_("E1096: Returning a value in a function without a return type")); |
1a393685e7ce
patch 8.2.1131: Vim9: error message for returning a value is not clear
Bram Moolenaar <Bram@vim.org>
parents:
21158
diff
changeset
|
4062 return NULL; |
1a393685e7ce
patch 8.2.1131: Vim9: error message for returning a value is not clear
Bram Moolenaar <Bram@vim.org>
parents:
21158
diff
changeset
|
4063 } |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21255
diff
changeset
|
4064 if (need_type(stack_type, cctx->ctx_ufunc->uf_ret_type, -1, |
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21255
diff
changeset
|
4065 cctx, FALSE) == FAIL) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4066 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
|
4067 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4068 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4069 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4070 { |
19860
37c4779ca8f5
patch 8.2.0486: Vim9: some code and error messages not tested
Bram Moolenaar <Bram@vim.org>
parents:
19858
diff
changeset
|
4071 // "set_return_type" cannot be TRUE, only used for a lambda which |
37c4779ca8f5
patch 8.2.0486: Vim9: some code and error messages not tested
Bram Moolenaar <Bram@vim.org>
parents:
19858
diff
changeset
|
4072 // 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
|
4073 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
|
4074 && 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
|
4075 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4076 emsg(_("E1003: Missing return value")); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4077 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4078 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4079 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4080 // 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
|
4081 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
|
4082 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4083 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4084 if (generate_instr(cctx, ISN_RETURN) == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4085 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4086 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4087 // "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
|
4088 return skipwhite(p); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4089 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4090 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4091 /* |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4092 * 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
|
4093 * 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
|
4094 * 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
|
4095 */ |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4096 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
|
4097 exarg_getline( |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4098 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
|
4099 void *cookie, |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4100 int indent UNUSED, |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4101 int do_concat UNUSED) |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4102 { |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4103 cctx_T *cctx = (cctx_T *)cookie; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4104 |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4105 if (cctx->ctx_lnum == cctx->ctx_ufunc->uf_lines.ga_len) |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4106 { |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4107 iemsg("Heredoc got to end"); |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4108 return NULL; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4109 } |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4110 ++cctx->ctx_lnum; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4111 return vim_strsave(((char_u **)cctx->ctx_ufunc->uf_lines.ga_data) |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4112 [cctx->ctx_lnum]); |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4113 } |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4114 |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4115 /* |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4116 * 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
|
4117 */ |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4118 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
|
4119 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
|
4120 { |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
4121 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
|
4122 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
|
4123 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
|
4124 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
|
4125 lvar_T *lvar; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4126 ufunc_T *ufunc; |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
4127 int r; |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4128 |
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
|
4129 // 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
|
4130 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
|
4131 { |
7028f45bf0ea
patch 8.2.1351: Vim9: no proper error if using namespace for nested function
Bram Moolenaar <Bram@vim.org>
parents:
21598
diff
changeset
|
4132 semsg(_(e_namespace), name_start); |
7028f45bf0ea
patch 8.2.1351: Vim9: no proper error if using namespace for nested function
Bram Moolenaar <Bram@vim.org>
parents:
21598
diff
changeset
|
4133 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
|
4134 } |
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
|
4135 if (check_defined(name_start, name_end - name_start, cctx) == FAIL) |
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21584
diff
changeset
|
4136 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
|
4137 |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4138 eap->arg = name_end; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4139 eap->getline = exarg_getline; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4140 eap->cookie = cctx; |
20907
4eeda7139133
patch 8.2.1005: Vim9: using TRUE/FALSE/MAYBE for ctx_skip is confusing
Bram Moolenaar <Bram@vim.org>
parents:
20899
diff
changeset
|
4141 eap->skip = cctx->ctx_skip == SKIP_YES; |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4142 eap->forceit = FALSE; |
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
|
4143 lambda_name = get_lambda_name(); |
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
|
4144 ufunc = def_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
|
4145 |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20419
diff
changeset
|
4146 if (ufunc == NULL) |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20419
diff
changeset
|
4147 return NULL; |
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
|
4148 if (ufunc->uf_def_status == UF_TO_BE_COMPILED |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20419
diff
changeset
|
4149 && compile_def_function(ufunc, TRUE, cctx) == FAIL) |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4150 return NULL; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4151 |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
4152 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
|
4153 { |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
4154 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
|
4155 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
|
4156 |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
4157 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
|
4158 r = FAIL; |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
4159 else |
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
|
4160 r = generate_NEWFUNC(cctx, lambda_name, 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
|
4161 } |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
4162 else |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
4163 { |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
4164 // Define a local variable for the function reference. |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
4165 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
|
4166 TRUE, ufunc->uf_func_type); |
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
|
4167 if (lvar == 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
|
4168 return NULL; |
21693
4e4fd845553d
patch 8.2.1396: Vim9: no error for unexpectedly returning a value
Bram Moolenaar <Bram@vim.org>
parents:
21691
diff
changeset
|
4169 if (generate_FUNCREF(cctx, ufunc) == FAIL) |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
4170 return NULL; |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
4171 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
|
4172 } |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4173 |
20305
9a5e2370df0e
patch 8.2.0708: Vim9: constant expressions are not simplified
Bram Moolenaar <Bram@vim.org>
parents:
20295
diff
changeset
|
4174 // TODO: warning for trailing text? |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
4175 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
|
4176 } |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4177 |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
4178 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4179 * 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
|
4180 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4181 int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4182 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
|
4183 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4184 if (*p == '=') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4185 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4186 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
|
4187 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4188 *heredoc = TRUE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4189 return 3; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4190 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4191 return 1; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4192 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4193 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
|
4194 return 2; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4195 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
|
4196 return 3; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4197 return 0; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4198 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4199 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4200 // 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
|
4201 static char *reserved[] = { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4202 "true", |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4203 "false", |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4204 NULL |
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 |
19285
86665583dc83
patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents:
19283
diff
changeset
|
4207 typedef enum { |
86665583dc83
patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents:
19283
diff
changeset
|
4208 dest_local, |
86665583dc83
patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents:
19283
diff
changeset
|
4209 dest_option, |
86665583dc83
patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents:
19283
diff
changeset
|
4210 dest_env, |
86665583dc83
patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents:
19283
diff
changeset
|
4211 dest_global, |
20089
7fc5d62fe2a5
patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents:
20079
diff
changeset
|
4212 dest_buffer, |
7fc5d62fe2a5
patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents:
20079
diff
changeset
|
4213 dest_window, |
7fc5d62fe2a5
patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents:
20079
diff
changeset
|
4214 dest_tab, |
19285
86665583dc83
patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents:
19283
diff
changeset
|
4215 dest_vimvar, |
86665583dc83
patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents:
19283
diff
changeset
|
4216 dest_script, |
86665583dc83
patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents:
19283
diff
changeset
|
4217 dest_reg, |
86665583dc83
patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents:
19283
diff
changeset
|
4218 } assign_dest_T; |
86665583dc83
patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents:
19283
diff
changeset
|
4219 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4220 /* |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4221 * 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
|
4222 */ |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4223 static void |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4224 generate_loadvar( |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4225 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
|
4226 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
|
4227 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
|
4228 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
|
4229 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
|
4230 { |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4231 switch (dest) |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4232 { |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4233 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
|
4234 // 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
|
4235 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
|
4236 break; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4237 case dest_global: |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4238 generate_LOAD(cctx, ISN_LOADG, 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
|
4239 break; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4240 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
|
4241 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
|
4242 break; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4243 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
|
4244 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
|
4245 break; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4246 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
|
4247 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
|
4248 break; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4249 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
|
4250 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
|
4251 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
|
4252 break; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4253 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
|
4254 // 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
|
4255 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
|
4256 break; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4257 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
|
4258 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
|
4259 break; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4260 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
|
4261 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
|
4262 break; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4263 case dest_local: |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4264 if (lvar->lv_from_outer) |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4265 generate_LOAD(cctx, ISN_LOADOUTER, lvar->lv_idx, |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4266 NULL, type); |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4267 else |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4268 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
|
4269 break; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4270 } |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4271 } |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4272 |
20953
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20949
diff
changeset
|
4273 void |
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20949
diff
changeset
|
4274 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
|
4275 { |
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20949
diff
changeset
|
4276 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
|
4277 |
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20949
diff
changeset
|
4278 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
|
4279 { |
20961
0e01976dfd3b
patch 8.2.1032: error message for declaring a variable cannot be translated
Bram Moolenaar <Bram@vim.org>
parents:
20955
diff
changeset
|
4280 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
|
4281 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
|
4282 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
|
4283 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
|
4284 case 'v': scope = "v:"; break; |
21610
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
4285 case '$': semsg(_(e_declare_env_var), name); |
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
4286 return; |
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
4287 case '&': semsg(_("E1052: Cannot declare an option: %s"), name); |
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
4288 return; |
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
4289 case '@': semsg(_("E1066: Cannot declare a register: %s"), name); |
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
4290 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
|
4291 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
|
4292 } |
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20949
diff
changeset
|
4293 semsg(_(e_declare_var), scope, name); |
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20949
diff
changeset
|
4294 } |
6b4b887a12f0
patch 8.2.1028: Vim9: no error for declaring buffer, window, etc. variable
Bram Moolenaar <Bram@vim.org>
parents:
20949
diff
changeset
|
4295 |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4296 /* |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4297 * Compile declaration and assignment: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4298 * "let var", "let var = expr", "const var = expr" and "var = expr" |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4299 * "arg" points to "var". |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4300 * 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
|
4301 * 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
|
4302 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4303 static char_u * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4304 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
|
4305 { |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4306 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
|
4307 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
|
4308 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
|
4309 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
|
4310 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
|
4311 int var_idx; |
21576
f4252efe370e
patch 8.2.1338: Vim9: assigning to script-local variable doesn't check type
Bram Moolenaar <Bram@vim.org>
parents:
21564
diff
changeset
|
4312 int scriptvar_sid = 0; |
f4252efe370e
patch 8.2.1338: Vim9: assigning to script-local variable doesn't check type
Bram Moolenaar <Bram@vim.org>
parents:
21564
diff
changeset
|
4313 int scriptvar_idx = -1; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4314 int semicolon = 0; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4315 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
|
4316 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
|
4317 char_u *op; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4318 int oplen = 0; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4319 int heredoc = FALSE; |
19872
8a7bede7b138
patch 8.2.0492: Vim9: some error messages not tested
Bram Moolenaar <Bram@vim.org>
parents:
19866
diff
changeset
|
4320 type_T *type = &t_any; |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4321 type_T *member_type = &t_any; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4322 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
|
4323 char_u *sp; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4324 int is_decl = cmdidx == CMD_let || cmdidx == CMD_const; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4325 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4326 // 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
|
4327 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
|
4328 if (p == NULL) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4329 return *arg == '[' ? arg : NULL; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4330 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4331 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
|
4332 { |
21421
0f0fee4122d3
patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents:
21411
diff
changeset
|
4333 // 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
|
4334 // members? |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4335 emsg(_("E1092: Cannot use a list for a declaration")); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4336 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4337 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4338 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4339 sp = p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4340 p = skipwhite(p); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4341 op = p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4342 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
|
4343 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4344 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
|
4345 // 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
|
4346 return arg; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4347 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4348 if (oplen > 0 && (!VIM_ISWHITE(*sp) || !VIM_ISWHITE(op[oplen]))) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4349 { |
21630
3c6c52fbc8ea
patch 8.2.1365: Vim9: no error for missing white space around operator
Bram Moolenaar <Bram@vim.org>
parents:
21614
diff
changeset
|
4350 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
|
4351 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
|
4352 } |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4353 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4354 if (heredoc) |
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 list_T *l; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4357 listitem_T *li; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4358 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4359 // [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
|
4360 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
|
4361 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
|
4362 l = heredoc_get(eap, op + 3, FALSE); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4363 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4364 // Push each line and the create the list. |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19926
diff
changeset
|
4365 FOR_ALL_LIST_ITEMS(l, li) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4366 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4367 generate_PUSHS(cctx, li->li_tv.vval.v_string); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4368 li->li_tv.vval.v_string = NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4369 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4370 generate_NEWLIST(cctx, l->lv_len); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4371 type = &t_list_string; |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4372 member_type = &t_list_string; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4373 list_free(l); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4374 p += STRLEN(p); |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4375 end = p; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4376 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4377 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
|
4378 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4379 // 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
|
4380 // list of variables below. |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4381 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4382 p = skipwhite(op + oplen); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4383 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
|
4384 return NULL; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4385 end = p; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4386 |
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
|
4387 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
|
4388 { |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4389 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
|
4390 |
19942
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19934
diff
changeset
|
4391 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
|
4392 : ((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
|
4393 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
|
4394 { |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4395 emsg(_(e_cannot_use_void)); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4396 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4397 } |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21255
diff
changeset
|
4398 if (need_type(stacktype, &t_list_any, -1, cctx, FALSE) == FAIL) |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4399 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
|
4400 // 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
|
4401 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
|
4402 semicolon); |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4403 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4404 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4405 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4406 /* |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4407 * 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
|
4408 * 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
|
4409 */ |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4410 if (var_count > 0) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4411 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
|
4412 else |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4413 var_start = arg; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4414 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
|
4415 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4416 char_u *var_end = skip_var_one(var_start, FALSE); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4417 size_t varlen; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4418 int new_local = FALSE; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4419 int opt_type; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4420 int opt_flags = 0; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4421 assign_dest_T dest = dest_local; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4422 int vimvaridx = -1; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4423 lvar_T *lvar = NULL; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4424 lvar_T arg_lvar; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4425 int has_type = FALSE; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4426 int has_index = FALSE; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4427 int instr_count = -1; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4428 |
21614
d0128ecd4341
patch 8.2.1357: Vim9: cannot assign to / register
Bram Moolenaar <Bram@vim.org>
parents:
21612
diff
changeset
|
4429 if (*var_start == '@') |
d0128ecd4341
patch 8.2.1357: Vim9: cannot assign to / register
Bram Moolenaar <Bram@vim.org>
parents:
21612
diff
changeset
|
4430 p = var_start + 2; |
d0128ecd4341
patch 8.2.1357: Vim9: cannot assign to / register
Bram Moolenaar <Bram@vim.org>
parents:
21612
diff
changeset
|
4431 else |
d0128ecd4341
patch 8.2.1357: Vim9: cannot assign to / register
Bram Moolenaar <Bram@vim.org>
parents:
21612
diff
changeset
|
4432 { |
d0128ecd4341
patch 8.2.1357: Vim9: cannot assign to / register
Bram Moolenaar <Bram@vim.org>
parents:
21612
diff
changeset
|
4433 p = (*var_start == '&' || *var_start == '$') |
d0128ecd4341
patch 8.2.1357: Vim9: cannot assign to / register
Bram Moolenaar <Bram@vim.org>
parents:
21612
diff
changeset
|
4434 ? var_start + 1 : var_start; |
d0128ecd4341
patch 8.2.1357: Vim9: cannot assign to / register
Bram Moolenaar <Bram@vim.org>
parents:
21612
diff
changeset
|
4435 p = to_name_end(p, TRUE); |
d0128ecd4341
patch 8.2.1357: Vim9: cannot assign to / register
Bram Moolenaar <Bram@vim.org>
parents:
21612
diff
changeset
|
4436 } |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4437 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4438 // "a: type" is declaring variable "a" with a type, not "a:". |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4439 if (is_decl && var_end == var_start + 2 && var_end[-1] == ':') |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4440 --var_end; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4441 if (is_decl && p == var_start + 2 && p[-1] == ':') |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4442 --p; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4443 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4444 varlen = p - var_start; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4445 vim_free(name); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4446 name = vim_strnsave(var_start, varlen); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4447 if (name == NULL) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4448 return NULL; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4449 if (!heredoc) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4450 type = &t_any; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4451 |
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
|
4452 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
|
4453 { |
21610
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
4454 int declare_error = FALSE; |
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
4455 |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4456 if (*var_start == '&') |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4457 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4458 int cc; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4459 long numval; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4460 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4461 dest = dest_option; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4462 if (cmdidx == CMD_const) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4463 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4464 emsg(_(e_const_option)); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4465 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4466 } |
21610
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
4467 declare_error = is_decl; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4468 p = var_start; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4469 p = find_option_end(&p, &opt_flags); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4470 if (p == NULL) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4471 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4472 // cannot happen? |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4473 emsg(_(e_letunexp)); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4474 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4475 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4476 cc = *p; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4477 *p = NUL; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4478 opt_type = get_option_value(var_start + 1, &numval, |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4479 NULL, opt_flags); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4480 *p = cc; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4481 if (opt_type == -3) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4482 { |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4483 semsg(_(e_unknown_option), var_start); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4484 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4485 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4486 if (opt_type == -2 || opt_type == 0) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4487 type = &t_string; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4488 else |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4489 type = &t_number; // both number and boolean option |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4490 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4491 else if (*var_start == '$') |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4492 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4493 dest = dest_env; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4494 type = &t_string; |
21610
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
4495 declare_error = is_decl; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4496 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4497 else if (*var_start == '@') |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4498 { |
21614
d0128ecd4341
patch 8.2.1357: Vim9: cannot assign to / register
Bram Moolenaar <Bram@vim.org>
parents:
21612
diff
changeset
|
4499 if (!valid_yank_reg(var_start[1], FALSE) || var_start[1] == '.') |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4500 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4501 emsg_invreg(var_start[1]); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4502 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4503 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4504 dest = dest_reg; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4505 type = &t_string; |
21610
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
4506 declare_error = is_decl; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4507 } |
21540
8e278698b1fe
patch 8.2.1320: Vim9: cannot declare some single letter variables
Bram Moolenaar <Bram@vim.org>
parents:
21516
diff
changeset
|
4508 else if (varlen > 1 && STRNCMP(var_start, "g:", 2) == 0) |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4509 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4510 dest = dest_global; |
21610
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
4511 declare_error = is_decl; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4512 } |
21540
8e278698b1fe
patch 8.2.1320: Vim9: cannot declare some single letter variables
Bram Moolenaar <Bram@vim.org>
parents:
21516
diff
changeset
|
4513 else if (varlen > 1 && STRNCMP(var_start, "b:", 2) == 0) |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4514 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4515 dest = dest_buffer; |
21610
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
4516 declare_error = is_decl; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4517 } |
21540
8e278698b1fe
patch 8.2.1320: Vim9: cannot declare some single letter variables
Bram Moolenaar <Bram@vim.org>
parents:
21516
diff
changeset
|
4518 else if (varlen > 1 && STRNCMP(var_start, "w:", 2) == 0) |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4519 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4520 dest = dest_window; |
21610
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
4521 declare_error = is_decl; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4522 } |
21540
8e278698b1fe
patch 8.2.1320: Vim9: cannot declare some single letter variables
Bram Moolenaar <Bram@vim.org>
parents:
21516
diff
changeset
|
4523 else if (varlen > 1 && STRNCMP(var_start, "t:", 2) == 0) |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4524 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4525 dest = dest_tab; |
21610
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
4526 declare_error = is_decl; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4527 } |
21540
8e278698b1fe
patch 8.2.1320: Vim9: cannot declare some single letter variables
Bram Moolenaar <Bram@vim.org>
parents:
21516
diff
changeset
|
4528 else if (varlen > 1 && STRNCMP(var_start, "v:", 2) == 0) |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4529 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4530 typval_T *vtv; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4531 int di_flags; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4532 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4533 vimvaridx = find_vim_var(name + 2, &di_flags); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4534 if (vimvaridx < 0) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4535 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4536 semsg(_(e_var_notfound), var_start); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4537 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4538 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4539 // We use the current value of "sandbox" here, is that OK? |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4540 if (var_check_ro(di_flags, name, FALSE)) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4541 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4542 dest = dest_vimvar; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4543 vtv = get_vim_var_tv(vimvaridx); |
21443
66386ca8a69f
patch 8.2.1272: Vim9: type not checked if declaration also assigns value
Bram Moolenaar <Bram@vim.org>
parents:
21441
diff
changeset
|
4544 type = typval2type_vimvar(vtv, cctx->ctx_type_list); |
21610
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
4545 declare_error = is_decl; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4546 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4547 else |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4548 { |
21576
f4252efe370e
patch 8.2.1338: Vim9: assigning to script-local variable doesn't check type
Bram Moolenaar <Bram@vim.org>
parents:
21564
diff
changeset
|
4549 int idx; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4550 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4551 for (idx = 0; reserved[idx] != NULL; ++idx) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4552 if (STRCMP(reserved[idx], name) == 0) |
19942
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19934
diff
changeset
|
4553 { |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4554 semsg(_("E1034: Cannot use reserved name %s"), name); |
19942
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19934
diff
changeset
|
4555 goto theend; |
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19934
diff
changeset
|
4556 } |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4557 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4558 lvar = lookup_local(var_start, varlen, cctx); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4559 if (lvar == NULL) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4560 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4561 CLEAR_FIELD(arg_lvar); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4562 if (lookup_arg(var_start, varlen, |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4563 &arg_lvar.lv_idx, &arg_lvar.lv_type, |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4564 &arg_lvar.lv_from_outer, cctx) == OK) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4565 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4566 if (is_decl) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4567 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4568 semsg(_(e_used_as_arg), name); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4569 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4570 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4571 lvar = &arg_lvar; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4572 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4573 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4574 if (lvar != NULL) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4575 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4576 if (is_decl) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4577 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4578 semsg(_("E1017: Variable already declared: %s"), name); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4579 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4580 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4581 else if (lvar->lv_const) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4582 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4583 semsg(_("E1018: Cannot assign to a constant: %s"), |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4584 name); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4585 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4586 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4587 } |
21646
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4588 else |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4589 { |
21646
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4590 int script_namespace = varlen > 1 |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4591 && STRNCMP(var_start, "s:", 2) == 0; |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4592 int script_var = (script_namespace |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4593 ? lookup_script(var_start + 2, varlen - 2) |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4594 : lookup_script(var_start, varlen)) == OK; |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4595 imported_T *import = |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4596 find_imported(var_start, varlen, cctx); |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4597 |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4598 if (script_namespace || script_var || import != NULL) |
19942
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19934
diff
changeset
|
4599 { |
21646
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4600 char_u *rawname = name + (name[1] == ':' ? 2 : 0); |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4601 |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4602 if (is_decl) |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4603 { |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4604 if (script_namespace) |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4605 semsg(_("E1101: Cannot declare a script variable in a function: %s"), |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4606 name); |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4607 else |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4608 semsg(_("E1054: Variable already declared in the script: %s"), |
21540
8e278698b1fe
patch 8.2.1320: Vim9: cannot declare some single letter variables
Bram Moolenaar <Bram@vim.org>
parents:
21516
diff
changeset
|
4609 name); |
21646
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4610 goto theend; |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4611 } |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4612 else if (cctx->ctx_ufunc->uf_script_ctx_version |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4613 == SCRIPT_VERSION_VIM9 |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4614 && script_namespace |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4615 && !script_var && import == NULL) |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4616 { |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4617 semsg(_(e_unknown_var), name); |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4618 goto theend; |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4619 } |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4620 |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4621 dest = dest_script; |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4622 |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4623 // existing script-local variables should have a type |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4624 scriptvar_sid = current_sctx.sc_sid; |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4625 if (import != NULL) |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4626 scriptvar_sid = import->imp_sid; |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4627 scriptvar_idx = get_script_item_idx(scriptvar_sid, |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4628 rawname, TRUE); |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4629 if (scriptvar_idx >= 0) |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4630 { |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4631 scriptitem_T *si = SCRIPT_ITEM(scriptvar_sid); |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4632 svar_T *sv = |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4633 ((svar_T *)si->sn_var_vals.ga_data) |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4634 + scriptvar_idx; |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4635 type = sv->sv_type; |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4636 } |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4637 } |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4638 else if (name[1] == ':' && name[2] != NUL) |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4639 { |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4640 semsg(_("E1082: Cannot use a namespaced variable: %s"), |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4641 name); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4642 goto theend; |
19942
b471038ec3ea
patch 8.2.0527: Vim9: function types insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19934
diff
changeset
|
4643 } |
21646
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4644 else if (!is_decl) |
21576
f4252efe370e
patch 8.2.1338: Vim9: assigning to script-local variable doesn't check type
Bram Moolenaar <Bram@vim.org>
parents:
21564
diff
changeset
|
4645 { |
21646
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4646 semsg(_(e_unknown_var), name); |
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21630
diff
changeset
|
4647 goto theend; |
21576
f4252efe370e
patch 8.2.1338: Vim9: assigning to script-local variable doesn't check type
Bram Moolenaar <Bram@vim.org>
parents:
21564
diff
changeset
|
4648 } |
21683
bb4f55d20951
patch 8.2.1391: Vim9: no error for shadowing a script function
Bram Moolenaar <Bram@vim.org>
parents:
21681
diff
changeset
|
4649 else if (check_defined(var_start, varlen, cctx) == FAIL) |
bb4f55d20951
patch 8.2.1391: Vim9: no error for shadowing a script function
Bram Moolenaar <Bram@vim.org>
parents:
21681
diff
changeset
|
4650 goto theend; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4651 } |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4652 } |
21610
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
4653 |
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
4654 if (declare_error) |
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
4655 { |
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
4656 vim9_declare_error(name); |
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
4657 goto theend; |
586241ee8096
patch 8.2.1355: Vim9: no error using :let for options and registers
Bram Moolenaar <Bram@vim.org>
parents:
21604
diff
changeset
|
4658 } |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4659 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4660 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4661 // handle "a:name" as a name, not index "name" on "a" |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4662 if (varlen > 1 || var_start[varlen] != ':') |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4663 p = var_end; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4664 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4665 if (dest != dest_option) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4666 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4667 if (is_decl && *p == ':') |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4668 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4669 // parse optional type: "let var: type = expr" |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4670 if (!VIM_ISWHITE(p[1])) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4671 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4672 semsg(_(e_white_after), ":"); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4673 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4674 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4675 p = skipwhite(p + 1); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4676 type = parse_type(&p, cctx->ctx_type_list); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4677 has_type = TRUE; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4678 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4679 else if (lvar != NULL) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4680 type = lvar->lv_type; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4681 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4682 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4683 if (oplen == 3 && !heredoc && dest != dest_global |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4684 && type->tt_type != VAR_STRING |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4685 && type->tt_type != VAR_ANY) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4686 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4687 emsg(_("E1019: Can only concatenate to string")); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4688 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4689 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4690 |
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
|
4691 if (lvar == NULL && dest == dest_local && cctx->ctx_skip != SKIP_YES) |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4692 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4693 if (oplen > 1 && !heredoc) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4694 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4695 // +=, /=, etc. require an existing variable |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4696 semsg(_("E1020: cannot use an operator on a new variable: %s"), |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4697 name); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4698 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4699 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4700 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4701 // new local variable |
21691
f41c646cb8b9
patch 8.2.1395: Vim9: no error if declaring a funcref with lower case letter
Bram Moolenaar <Bram@vim.org>
parents:
21689
diff
changeset
|
4702 if ((type->tt_type == VAR_FUNC || type->tt_type == VAR_PARTIAL) |
f41c646cb8b9
patch 8.2.1395: Vim9: no error if declaring a funcref with lower case letter
Bram Moolenaar <Bram@vim.org>
parents:
21689
diff
changeset
|
4703 && var_wrong_func_name(name, TRUE)) |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4704 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4705 lvar = reserve_local(cctx, var_start, varlen, |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4706 cmdidx == CMD_const, type); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4707 if (lvar == NULL) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4708 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4709 new_local = TRUE; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4710 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4711 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4712 member_type = type; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4713 if (var_end > var_start + varlen) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4714 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4715 // Something follows after the variable: "var[idx]". |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4716 if (is_decl) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4717 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4718 emsg(_("E1087: cannot use an index when declaring a variable")); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4719 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4720 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4721 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4722 if (var_start[varlen] == '[') |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4723 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4724 has_index = TRUE; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4725 if (type->tt_member == NULL) |
21578
7417cb54cb24
patch 8.2.1339: Vim9: assigning to global dict variable doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21576
diff
changeset
|
4726 member_type = &t_any; |
7417cb54cb24
patch 8.2.1339: Vim9: assigning to global dict variable doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21576
diff
changeset
|
4727 else |
7417cb54cb24
patch 8.2.1339: Vim9: assigning to global dict variable doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21576
diff
changeset
|
4728 member_type = type->tt_member; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4729 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4730 else |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4731 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4732 semsg("Not supported yet: %s", var_start); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4733 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4734 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4735 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4736 else if (lvar == &arg_lvar) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4737 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4738 semsg(_("E1090: Cannot assign to argument %s"), name); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4739 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4740 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4741 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4742 if (!heredoc) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4743 { |
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
|
4744 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
|
4745 { |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4746 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
|
4747 { |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4748 // 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
|
4749 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
|
4750 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
|
4751 } |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4752 } |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4753 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
|
4754 { |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4755 type_T *stacktype; |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4756 |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4757 // 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
|
4758 if (var_count == 0) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4759 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4760 int r; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4761 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4762 // 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
|
4763 if (*op != '=') |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4764 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4765 generate_loadvar(cctx, dest, name, lvar, type); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4766 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4767 if (has_index) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4768 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4769 // TODO: get member from list or dict |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4770 emsg("Index with operation not supported yet"); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4771 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4772 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4773 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4774 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4775 // 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
|
4776 // variable here, it is not available to this expression. |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4777 if (new_local) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4778 --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
|
4779 instr_count = instr->ga_len; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4780 p = skipwhite(op + oplen); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4781 r = compile_expr0(&p, cctx); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4782 if (new_local) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4783 ++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
|
4784 if (r == FAIL) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4785 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4786 } |
20871
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
4787 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
|
4788 { |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
4789 // 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
|
4790 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
|
4791 goto theend; |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
4792 } |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4793 else |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4794 { |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4795 // 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
|
4796 // list. |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4797 if (generate_GETITEM(cctx, var_idx) == FAIL) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4798 return FAIL; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4799 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4800 |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4801 stacktype = 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
|
4802 : ((type_T **)stack->ga_data)[stack->ga_len - 1]; |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4803 if (lvar != NULL && (is_decl || !has_type)) |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4804 { |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4805 if (new_local && !has_type) |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4806 { |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4807 if (stacktype->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
|
4808 { |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4809 emsg(_(e_cannot_use_void)); |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4810 goto theend; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4811 } |
21691
f41c646cb8b9
patch 8.2.1395: Vim9: no error if declaring a funcref with lower case letter
Bram Moolenaar <Bram@vim.org>
parents:
21689
diff
changeset
|
4812 else if ((stacktype->tt_type == VAR_FUNC |
f41c646cb8b9
patch 8.2.1395: Vim9: no error if declaring a funcref with lower case letter
Bram Moolenaar <Bram@vim.org>
parents:
21689
diff
changeset
|
4813 || stacktype->tt_type == VAR_PARTIAL) |
f41c646cb8b9
patch 8.2.1395: Vim9: no error if declaring a funcref with lower case letter
Bram Moolenaar <Bram@vim.org>
parents:
21689
diff
changeset
|
4814 && var_wrong_func_name(name, TRUE)) |
f41c646cb8b9
patch 8.2.1395: Vim9: no error if declaring a funcref with lower case letter
Bram Moolenaar <Bram@vim.org>
parents:
21689
diff
changeset
|
4815 { |
f41c646cb8b9
patch 8.2.1395: Vim9: no error if declaring a funcref with lower case letter
Bram Moolenaar <Bram@vim.org>
parents:
21689
diff
changeset
|
4816 goto theend; |
f41c646cb8b9
patch 8.2.1395: Vim9: no error if declaring a funcref with lower case letter
Bram Moolenaar <Bram@vim.org>
parents:
21689
diff
changeset
|
4817 } |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4818 else |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4819 { |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4820 // An empty list or dict has a &t_void member, |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4821 // for a variable that implies &t_any. |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4822 if (stacktype == &t_list_empty) |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4823 lvar->lv_type = &t_list_any; |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4824 else if (stacktype == &t_dict_empty) |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4825 lvar->lv_type = &t_dict_any; |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4826 else |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4827 lvar->lv_type = stacktype; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4828 } |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4829 } |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4830 else |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4831 { |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4832 type_T *use_type = lvar->lv_type; |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4833 |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4834 if (has_index) |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4835 { |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4836 use_type = use_type->tt_member; |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4837 if (use_type == NULL) |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4838 use_type = &t_void; |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4839 } |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21255
diff
changeset
|
4840 if (need_type(stacktype, use_type, -1, cctx, FALSE) |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4841 == FAIL) |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4842 goto theend; |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4843 } |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4844 } |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4845 else if (*p != '=' && need_type(stacktype, member_type, -1, |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21255
diff
changeset
|
4846 cctx, FALSE) == FAIL) |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4847 goto theend; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4848 } |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4849 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
|
4850 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4851 emsg(_(e_const_req_value)); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4852 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4853 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4854 else if (!has_type || dest == dest_option) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4855 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4856 emsg(_(e_type_req)); |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
4857 goto theend; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4858 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4859 else |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4860 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4861 // variables are always initialized |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4862 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
|
4863 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4864 switch (member_type->tt_type) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4865 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4866 case VAR_BOOL: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4867 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
|
4868 break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4869 case VAR_FLOAT: |
19336
1cd6eab65ce0
patch 8.2.0226: compiling for loop not tested
Bram Moolenaar <Bram@vim.org>
parents:
19332
diff
changeset
|
4870 #ifdef FEAT_FLOAT |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4871 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
|
4872 #endif |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4873 break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4874 case VAR_STRING: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4875 generate_PUSHS(cctx, NULL); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4876 break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4877 case VAR_BLOB: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4878 generate_PUSHBLOB(cctx, NULL); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4879 break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4880 case VAR_FUNC: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4881 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
|
4882 break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4883 case VAR_LIST: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4884 generate_NEWLIST(cctx, 0); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4885 break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4886 case VAR_DICT: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4887 generate_NEWDICT(cctx, 0); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4888 break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4889 case VAR_JOB: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4890 generate_PUSHJOB(cctx, NULL); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4891 break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4892 case VAR_CHANNEL: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4893 generate_PUSHCHANNEL(cctx, NULL); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4894 break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4895 case VAR_NUMBER: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4896 case VAR_UNKNOWN: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4897 case VAR_ANY: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4898 case VAR_PARTIAL: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4899 case VAR_VOID: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4900 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
|
4901 generate_PUSHNR(cctx, 0); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4902 break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4903 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4904 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4905 if (var_count == 0) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4906 end = p; |
19336
1cd6eab65ce0
patch 8.2.0226: compiling for loop not tested
Bram Moolenaar <Bram@vim.org>
parents:
19332
diff
changeset
|
4907 } |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4908 |
20899
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4909 // 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
|
4910 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
|
4911 break; |
e76bddcf3341
patch 8.2.1001: Vim9: crash with nested "if" and assignment
Bram Moolenaar <Bram@vim.org>
parents:
20871
diff
changeset
|
4912 |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4913 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
|
4914 { |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4915 type_T *expected = &t_number; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4916 type_T *stacktype; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4917 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4918 // TODO: if type is known use float or any operation |
21677
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
4919 // TODO: check operator matches variable type |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4920 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4921 if (*op == '.') |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4922 expected = &t_string; |
21677
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
4923 else if (*op == '+') |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
4924 expected = member_type; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4925 stacktype = ((type_T **)stack->ga_data)[stack->ga_len - 1]; |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21255
diff
changeset
|
4926 if (need_type(stacktype, expected, -1, cctx, FALSE) == FAIL) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4927 goto theend; |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4928 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4929 if (*op == '.') |
21677
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
4930 { |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
4931 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
|
4932 goto theend; |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
4933 } |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
4934 else if (*op == '+') |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
4935 { |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
4936 if (generate_add_instr(cctx, |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
4937 operator_type(member_type, stacktype), |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
4938 member_type, stacktype) == FAIL) |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
4939 goto theend; |
84d38f98e5de
patch 8.2.1388: Vim9: += only works for numbers
Bram Moolenaar <Bram@vim.org>
parents:
21650
diff
changeset
|
4940 } |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4941 else |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4942 { |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4943 isn_T *isn = generate_instr_drop(cctx, ISN_OPNR, 1); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4944 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4945 if (isn == NULL) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4946 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4947 switch (*op) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4948 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4949 case '-': isn->isn_arg.op.op_type = EXPR_SUB; break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4950 case '*': isn->isn_arg.op.op_type = EXPR_MULT; break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4951 case '/': isn->isn_arg.op.op_type = EXPR_DIV; break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4952 case '%': isn->isn_arg.op.op_type = EXPR_REM; break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4953 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4954 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4955 } |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4956 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4957 if (has_index) |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4958 { |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4959 int r; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4960 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4961 // Compile the "idx" in "var[idx]". |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4962 if (new_local) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4963 --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
|
4964 p = skipwhite(var_start + varlen + 1); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4965 r = compile_expr0(&p, cctx); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4966 if (new_local) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4967 ++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
|
4968 if (r == FAIL) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4969 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4970 if (*skipwhite(p) != ']') |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4971 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4972 emsg(_(e_missbrac)); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4973 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4974 } |
21578
7417cb54cb24
patch 8.2.1339: Vim9: assigning to global dict variable doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21576
diff
changeset
|
4975 if (type == &t_any) |
7417cb54cb24
patch 8.2.1339: Vim9: assigning to global dict variable doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21576
diff
changeset
|
4976 { |
7417cb54cb24
patch 8.2.1339: Vim9: assigning to global dict variable doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21576
diff
changeset
|
4977 type_T *idx_type = ((type_T **)stack->ga_data)[ |
7417cb54cb24
patch 8.2.1339: Vim9: assigning to global dict variable doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21576
diff
changeset
|
4978 stack->ga_len - 1]; |
7417cb54cb24
patch 8.2.1339: Vim9: assigning to global dict variable doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21576
diff
changeset
|
4979 // Index on variable of unknown type: guess the type from the |
7417cb54cb24
patch 8.2.1339: Vim9: assigning to global dict variable doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21576
diff
changeset
|
4980 // index type: number is dict, otherwise dict. |
7417cb54cb24
patch 8.2.1339: Vim9: assigning to global dict variable doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21576
diff
changeset
|
4981 // TODO: should do the assignment at runtime |
7417cb54cb24
patch 8.2.1339: Vim9: assigning to global dict variable doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21576
diff
changeset
|
4982 if (idx_type->tt_type == VAR_NUMBER) |
7417cb54cb24
patch 8.2.1339: Vim9: assigning to global dict variable doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21576
diff
changeset
|
4983 type = &t_list_any; |
7417cb54cb24
patch 8.2.1339: Vim9: assigning to global dict variable doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21576
diff
changeset
|
4984 else |
7417cb54cb24
patch 8.2.1339: Vim9: assigning to global dict variable doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21576
diff
changeset
|
4985 type = &t_dict_any; |
7417cb54cb24
patch 8.2.1339: Vim9: assigning to global dict variable doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21576
diff
changeset
|
4986 } |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4987 if (type->tt_type == VAR_DICT |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4988 && may_generate_2STRING(-1, cctx) == FAIL) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4989 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4990 if (type->tt_type == VAR_LIST |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4991 && ((type_T **)stack->ga_data)[stack->ga_len - 1]->tt_type |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
4992 != VAR_NUMBER) |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4993 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4994 emsg(_(e_number_exp)); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4995 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4996 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4997 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4998 // Load the dict or list. On the stack we then have: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
4999 // - value |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5000 // - index |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5001 // - variable |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5002 generate_loadvar(cctx, dest, name, lvar, type); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5003 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5004 if (type->tt_type == VAR_LIST) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5005 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5006 if (generate_instr_drop(cctx, ISN_STORELIST, 3) == FAIL) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5007 return FAIL; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5008 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5009 else if (type->tt_type == VAR_DICT) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5010 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5011 if (generate_instr_drop(cctx, ISN_STOREDICT, 3) == FAIL) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5012 return FAIL; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5013 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5014 else |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5015 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5016 emsg(_(e_listreq)); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5017 goto theend; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5018 } |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
5019 } |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
5020 else |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
5021 { |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5022 switch (dest) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5023 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5024 case dest_option: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5025 generate_STOREOPT(cctx, name + 1, opt_flags); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5026 break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5027 case dest_global: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5028 // include g: with the name, easier to execute that way |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5029 generate_STORE(cctx, ISN_STOREG, 0, name); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5030 break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5031 case dest_buffer: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5032 // include b: with the name, easier to execute that way |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5033 generate_STORE(cctx, ISN_STOREB, 0, name); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5034 break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5035 case dest_window: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5036 // include w: with the name, easier to execute that way |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5037 generate_STORE(cctx, ISN_STOREW, 0, name); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5038 break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5039 case dest_tab: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5040 // include t: with the name, easier to execute that way |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5041 generate_STORE(cctx, ISN_STORET, 0, name); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5042 break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5043 case dest_env: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5044 generate_STORE(cctx, ISN_STOREENV, 0, name + 1); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5045 break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5046 case dest_reg: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5047 generate_STORE(cctx, ISN_STOREREG, name[1], NULL); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5048 break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5049 case dest_vimvar: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5050 generate_STORE(cctx, ISN_STOREV, vimvaridx, NULL); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5051 break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5052 case dest_script: |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
5053 { |
21576
f4252efe370e
patch 8.2.1338: Vim9: assigning to script-local variable doesn't check type
Bram Moolenaar <Bram@vim.org>
parents:
21564
diff
changeset
|
5054 if (scriptvar_idx < 0) |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5055 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5056 char_u *name_s = name; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5057 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5058 // Include s: in the name for store_var() |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5059 if (name[1] != ':') |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5060 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5061 int len = (int)STRLEN(name) + 3; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5062 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5063 name_s = alloc(len); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5064 if (name_s == NULL) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5065 name_s = name; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5066 else |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5067 vim_snprintf((char *)name_s, len, |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5068 "s:%s", name); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5069 } |
21576
f4252efe370e
patch 8.2.1338: Vim9: assigning to script-local variable doesn't check type
Bram Moolenaar <Bram@vim.org>
parents:
21564
diff
changeset
|
5070 generate_OLDSCRIPT(cctx, ISN_STORES, name_s, |
f4252efe370e
patch 8.2.1338: Vim9: assigning to script-local variable doesn't check type
Bram Moolenaar <Bram@vim.org>
parents:
21564
diff
changeset
|
5071 scriptvar_sid, type); |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5072 if (name_s != name) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5073 vim_free(name_s); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5074 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5075 else |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5076 generate_VIM9SCRIPT(cctx, ISN_STORESCRIPT, |
21576
f4252efe370e
patch 8.2.1338: Vim9: assigning to script-local variable doesn't check type
Bram Moolenaar <Bram@vim.org>
parents:
21564
diff
changeset
|
5077 scriptvar_sid, scriptvar_idx, type); |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5078 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5079 break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5080 case dest_local: |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5081 if (lvar != NULL) |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
5082 { |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5083 isn_T *isn = ((isn_T *)instr->ga_data) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5084 + instr->ga_len - 1; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5085 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5086 // optimization: turn "var = 123" from ISN_PUSHNR + |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5087 // ISN_STORE into ISN_STORENR |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5088 if (!lvar->lv_from_outer |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5089 && instr->ga_len == instr_count + 1 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5090 && isn->isn_type == ISN_PUSHNR) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5091 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5092 varnumber_T val = isn->isn_arg.number; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5093 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5094 isn->isn_type = ISN_STORENR; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5095 isn->isn_arg.storenr.stnr_idx = lvar->lv_idx; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5096 isn->isn_arg.storenr.stnr_val = val; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5097 if (stack->ga_len > 0) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5098 --stack->ga_len; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5099 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5100 else if (lvar->lv_from_outer) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5101 generate_STORE(cctx, ISN_STOREOUTER, lvar->lv_idx, |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5102 NULL); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5103 else |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5104 generate_STORE(cctx, ISN_STORE, lvar->lv_idx, NULL); |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
5105 } |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5106 break; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5107 } |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
5108 } |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5109 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5110 if (var_idx + 1 < var_count) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5111 var_start = skipwhite(var_end + 1); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5112 } |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5113 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5114 // 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
|
5115 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
|
5116 { |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
5117 if (generate_instr_drop(cctx, ISN_DROP, 1) == NULL) |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
5118 goto theend; |
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
5119 } |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
5120 |
21391
8b882afa8ed2
patch 8.2.1246: Vim9: comment after assignment doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
21387
diff
changeset
|
5121 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
|
5122 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5123 theend: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5124 vim_free(name); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5125 return ret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5126 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5127 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5128 /* |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5129 * 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
|
5130 */ |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5131 int |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5132 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
|
5133 { |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5134 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
|
5135 { |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5136 semsg(_("E1081: Cannot unlet %s"), name); |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5137 return FAIL; |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5138 } |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5139 return OK; |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5140 } |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5141 |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5142 /* |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5143 * Callback passed to ex_unletlock(). |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5144 */ |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5145 static int |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5146 compile_unlet( |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5147 lval_T *lvp, |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5148 char_u *name_end, |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5149 exarg_T *eap, |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5150 int deep UNUSED, |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5151 void *coookie) |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5152 { |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5153 cctx_T *cctx = coookie; |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5154 |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5155 if (lvp->ll_tv == NULL) |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5156 { |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5157 char_u *p = lvp->ll_name; |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5158 int cc = *name_end; |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5159 int ret = OK; |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5160 |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5161 // Normal name. Only supports g:, w:, t: and b: namespaces. |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5162 *name_end = NUL; |
20099
058b41f85bcb
patch 8.2.0605: Vim9: cannot unlet an environment variable
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
5163 if (*p == '$') |
058b41f85bcb
patch 8.2.0605: Vim9: cannot unlet an environment variable
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
5164 ret = generate_UNLET(cctx, ISN_UNLETENV, p + 1, eap->forceit); |
058b41f85bcb
patch 8.2.0605: Vim9: cannot unlet an environment variable
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
5165 else if (check_vim9_unlet(p) == FAIL) |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5166 ret = FAIL; |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5167 else |
20099
058b41f85bcb
patch 8.2.0605: Vim9: cannot unlet an environment variable
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
5168 ret = generate_UNLET(cctx, ISN_UNLET, p, eap->forceit); |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5169 |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5170 *name_end = cc; |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5171 return ret; |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5172 } |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5173 |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5174 // TODO: unlet {list}[idx] |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5175 // TODO: unlet {dict}[key] |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5176 emsg("Sorry, :unlet not fully implemented yet"); |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5177 return FAIL; |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5178 } |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5179 |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5180 /* |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5181 * 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
|
5182 * "arg" points to "var". |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5183 */ |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5184 static char_u * |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5185 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
|
5186 { |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5187 char_u *p = arg; |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5188 |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5189 if (eap->cmdidx != CMD_unlet) |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5190 { |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5191 emsg("Sorry, :lock and unlock not implemented yet"); |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5192 return NULL; |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5193 } |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5194 |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5195 if (*p == '!') |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5196 { |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5197 p = skipwhite(p + 1); |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5198 eap->forceit = TRUE; |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5199 } |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5200 |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5201 ex_unletlock(eap, p, 0, GLV_NO_AUTOLOAD, compile_unlet, cctx); |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5202 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
|
5203 } |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5204 |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
5205 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5206 * 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
|
5207 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5208 static char_u * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5209 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
|
5210 { |
21146
465d6e40e79c
patch 8.2.1124: Vim9: no line break allowed in :import command
Bram Moolenaar <Bram@vim.org>
parents:
21120
diff
changeset
|
5211 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
|
5212 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5213 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5214 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5215 * 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
|
5216 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5217 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5218 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
|
5219 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5220 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
|
5221 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
|
5222 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5223 if (endlabel == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5224 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5225 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
|
5226 *el = endlabel; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5227 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
|
5228 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5229 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
|
5230 return OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5231 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5232 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5233 static void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5234 compile_fill_jump_to_end(endlabel_T **el, cctx_T *cctx) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5235 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5236 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
|
5237 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5238 while (*el != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5239 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5240 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
|
5241 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5242 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5243 isn = ((isn_T *)instr->ga_data) + cur->el_end_label; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5244 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
|
5245 *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
|
5246 vim_free(cur); |
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 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5249 |
19896
92177b596695
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
19894
diff
changeset
|
5250 static void |
92177b596695
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
19894
diff
changeset
|
5251 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
|
5252 { |
92177b596695
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
19894
diff
changeset
|
5253 while (*el != NULL) |
92177b596695
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
19894
diff
changeset
|
5254 { |
92177b596695
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
19894
diff
changeset
|
5255 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
|
5256 |
92177b596695
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
19894
diff
changeset
|
5257 *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
|
5258 vim_free(cur); |
92177b596695
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
19894
diff
changeset
|
5259 } |
92177b596695
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
19894
diff
changeset
|
5260 } |
92177b596695
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
19894
diff
changeset
|
5261 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5262 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5263 * 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
|
5264 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5265 static scope_T * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5266 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
|
5267 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5268 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
|
5269 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5270 if (scope == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5271 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5272 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
|
5273 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
|
5274 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
|
5275 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
|
5276 return scope; |
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 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5279 /* |
19866
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5280 * 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
|
5281 */ |
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5282 static void |
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5283 drop_scope(cctx_T *cctx) |
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5284 { |
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5285 scope_T *scope = cctx->ctx_scope; |
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5286 |
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5287 if (scope == NULL) |
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5288 { |
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5289 iemsg("calling drop_scope() without a scope"); |
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5290 return; |
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5291 } |
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5292 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
|
5293 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
|
5294 { |
92177b596695
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
19894
diff
changeset
|
5295 case IF_SCOPE: |
92177b596695
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
19894
diff
changeset
|
5296 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
|
5297 case FOR_SCOPE: |
92177b596695
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
19894
diff
changeset
|
5298 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
|
5299 case WHILE_SCOPE: |
92177b596695
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
19894
diff
changeset
|
5300 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
|
5301 case TRY_SCOPE: |
92177b596695
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
19894
diff
changeset
|
5302 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
|
5303 case NO_SCOPE: |
92177b596695
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
19894
diff
changeset
|
5304 case BLOCK_SCOPE: |
92177b596695
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
19894
diff
changeset
|
5305 break; |
92177b596695
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
19894
diff
changeset
|
5306 } |
19866
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5307 vim_free(scope); |
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5308 } |
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5309 |
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5310 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5311 * compile "if expr" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5312 * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5313 * "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
|
5314 * 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
|
5315 * 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
|
5316 * ... body ... |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5317 * end: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5318 * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5319 * "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
|
5320 * 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
|
5321 * 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
|
5322 * ... body ... |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5323 * JUMP_ALWAYS end |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5324 * else: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5325 * ... body ... |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5326 * end: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5327 * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5328 * "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
|
5329 * 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
|
5330 * 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
|
5331 * ... body ... |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5332 * JUMP_ALWAYS end |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5333 * elseif: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5334 * 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
|
5335 * 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
|
5336 * ... body ... |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5337 * JUMP_ALWAYS end |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5338 * else: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5339 * ... body ... |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5340 * end: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5341 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5342 static char_u * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5343 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
|
5344 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5345 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
|
5346 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
|
5347 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
|
5348 scope_T *scope; |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
5349 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
|
5350 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
|
5351 |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
5352 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
|
5353 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
|
5354 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
5355 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
|
5356 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
|
5357 } |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
5358 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
|
5359 clear_ppconst(&ppconst); |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
5360 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
|
5361 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
5362 // The expression results in a constant. |
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
|
5363 cctx->ctx_skip = tv2bool(&ppconst.pp_tv[0]) ? 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
|
5364 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
|
5365 } |
19253
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
5366 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
|
5367 { |
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
5368 // 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
|
5369 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
|
5370 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
|
5371 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
|
5372 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5373 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5374 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
|
5375 if (scope == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5376 return NULL; |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
5377 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
|
5378 // "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
|
5379 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
|
5380 |
20933
e2fd5f05342f
patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents:
20929
diff
changeset
|
5381 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
|
5382 { |
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
5383 // "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
|
5384 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
|
5385 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
|
5386 } |
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
5387 else |
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
5388 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
|
5389 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5390 return p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5391 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5392 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5393 static char_u * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5394 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
|
5395 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5396 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
|
5397 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
|
5398 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
|
5399 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5400 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
|
5401 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
|
5402 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5403 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
|
5404 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5405 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
|
5406 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5407 } |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
5408 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
|
5409 if (!cctx->ctx_had_return) |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
5410 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
|
5411 |
20933
e2fd5f05342f
patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents:
20929
diff
changeset
|
5412 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
|
5413 { |
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
5414 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
|
5415 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
|
5416 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
|
5417 // 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
|
5418 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
|
5419 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
|
5420 } |
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
5421 |
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
5422 // 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
|
5423 CLEAR_FIELD(ppconst); |
b774655968b4
patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents:
20332
diff
changeset
|
5424 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
|
5425 { |
b774655968b4
patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents:
20332
diff
changeset
|
5426 clear_ppconst(&ppconst); |
b774655968b4
patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents:
20332
diff
changeset
|
5427 return NULL; |
b774655968b4
patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents:
20332
diff
changeset
|
5428 } |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
5429 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
|
5430 clear_ppconst(&ppconst); |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
5431 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
|
5432 { |
b774655968b4
patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents:
20332
diff
changeset
|
5433 // 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
|
5434 // TODO: how about nesting? |
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
|
5435 cctx->ctx_skip = tv2bool(&ppconst.pp_tv[0]) ? 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
|
5436 clear_ppconst(&ppconst); |
b774655968b4
patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents:
20332
diff
changeset
|
5437 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
|
5438 } |
19253
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
5439 else |
20334
b774655968b4
patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents:
20332
diff
changeset
|
5440 { |
b774655968b4
patch 8.2.0722: Vim9: not handling constant expression for elseif
Bram Moolenaar <Bram@vim.org>
parents:
20332
diff
changeset
|
5441 // 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
|
5442 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
|
5443 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
|
5444 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
|
5445 |
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
5446 // "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
|
5447 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
|
5448 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
|
5449 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5450 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5451 return p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5452 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5453 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5454 static char_u * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5455 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
|
5456 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5457 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
|
5458 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
|
5459 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5460 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
|
5461 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5462 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
|
5463 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5464 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
|
5465 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5466 } |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
5467 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
|
5468 if (!cctx->ctx_had_return) |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
5469 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
|
5470 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
|
5471 |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
5472 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
|
5473 { |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
5474 // 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
|
5475 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
|
5476 { |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
5477 if (!cctx->ctx_had_return |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
5478 && 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
|
5479 JUMP_ALWAYS, cctx) == FAIL) |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
5480 return NULL; |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
5481 } |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
5482 |
20933
e2fd5f05342f
patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents:
20929
diff
changeset
|
5483 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
|
5484 { |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
5485 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
|
5486 { |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
5487 // 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
|
5488 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
|
5489 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
|
5490 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
|
5491 } |
19253
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
5492 } |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
5493 |
20933
e2fd5f05342f
patch 8.2.1018: typo in enum value
Bram Moolenaar <Bram@vim.org>
parents:
20929
diff
changeset
|
5494 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
|
5495 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
|
5496 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5497 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5498 return p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5499 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5500 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5501 static char_u * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5502 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
|
5503 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5504 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
|
5505 ifscope_T *ifscope; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5506 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
|
5507 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5508 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5509 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
|
5510 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5511 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
|
5512 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5513 } |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19223
diff
changeset
|
5514 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
|
5515 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
|
5516 if (!cctx->ctx_had_return) |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
5517 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
|
5518 |
19253
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
5519 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
|
5520 { |
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
5521 // 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
|
5522 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
|
5523 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
|
5524 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5525 // Fill in the "end" label in jumps at the end of the blocks. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5526 compile_fill_jump_to_end(&ifscope->is_end_label, cctx); |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
5527 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
|
5528 |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
5529 // 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
|
5530 // had_return flag is set. |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
5531 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
|
5532 |
19866
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5533 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
|
5534 return arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5535 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5536 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5537 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5538 * compile "for var in expr" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5539 * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5540 * Produces instructions: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5541 * PUSHNR -1 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5542 * STORE loop-idx Set index to -1 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5543 * 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
|
5544 * 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
|
5545 * - 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
|
5546 * - 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
|
5547 * 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
|
5548 * ... body ... |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5549 * 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
|
5550 * 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
|
5551 * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5552 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5553 static char_u * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5554 compile_for(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
|
5555 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5556 char_u *p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5557 size_t varlen; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5558 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
|
5559 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
|
5560 scope_T *scope; |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
5561 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
|
5562 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
|
5563 type_T *vartype; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5564 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5565 // TODO: list of variables: "for [key, value] in dict" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5566 // parse "var" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5567 for (p = arg; eval_isnamec1(*p); ++p) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5568 ; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5569 varlen = p - arg; |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
5570 var_lvar = lookup_local(arg, varlen, cctx); |
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
5571 if (var_lvar != NULL) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5572 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5573 semsg(_("E1023: variable already defined: %s"), arg); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5574 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5575 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5576 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5577 // consume "in" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5578 p = skipwhite(p); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5579 if (STRNCMP(p, "in", 2) != 0 || !VIM_ISWHITE(p[2])) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5580 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5581 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
|
5582 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5583 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5584 p = skipwhite(p + 2); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5585 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5586 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5587 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
|
5588 if (scope == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5589 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5590 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5591 // Reserve a variable to store the loop iteration counter. |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
5592 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
|
5593 if (loop_lvar == NULL) |
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
5594 { |
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
5595 // out of memory |
19866
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5596 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
|
5597 return NULL; |
19866
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5598 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5599 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5600 // Reserve a variable to store "var" |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
5601 var_lvar = reserve_local(cctx, arg, varlen, FALSE, &t_any); |
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
5602 if (var_lvar == NULL) |
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
5603 { |
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
5604 // out of memory or used as an argument |
19866
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5605 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
|
5606 return NULL; |
19866
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5607 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5608 |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
5609 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
|
5610 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5611 // 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
|
5612 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
|
5613 if (compile_expr0(&arg, cctx) == FAIL) |
19866
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5614 { |
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5615 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
|
5616 return NULL; |
19866
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5617 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5618 |
21188
d73b6ba20053
patch 8.2.1145: Vim9: "for" only accepts a list at compile time
Bram Moolenaar <Bram@vim.org>
parents:
21172
diff
changeset
|
5619 // Now that we know the type of "var", check that it is a list, now or at |
d73b6ba20053
patch 8.2.1145: Vim9: "for" only accepts a list at compile time
Bram Moolenaar <Bram@vim.org>
parents:
21172
diff
changeset
|
5620 // runtime. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5621 vartype = ((type_T **)stack->ga_data)[stack->ga_len - 1]; |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21255
diff
changeset
|
5622 if (need_type(vartype, &t_list_any, -1, cctx, FALSE) == FAIL) |
21188
d73b6ba20053
patch 8.2.1145: Vim9: "for" only accepts a list at compile time
Bram Moolenaar <Bram@vim.org>
parents:
21172
diff
changeset
|
5623 { |
19866
1136ec381dd2
patch 8.2.0489: Vim9: memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19864
diff
changeset
|
5624 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
|
5625 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5626 } |
21188
d73b6ba20053
patch 8.2.1145: Vim9: "for" only accepts a list at compile time
Bram Moolenaar <Bram@vim.org>
parents:
21172
diff
changeset
|
5627 if (vartype->tt_type == VAR_LIST && vartype->tt_member->tt_type != VAR_ANY) |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
5628 var_lvar->lv_type = vartype->tt_member; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5629 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5630 // "for_end" is set when ":endfor" is found |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19223
diff
changeset
|
5631 scope->se_u.se_for.fs_top_label = instr->ga_len; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5632 |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
5633 generate_FOR(cctx, loop_lvar->lv_idx); |
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
5634 generate_STORE(cctx, ISN_STORE, var_lvar->lv_idx, NULL); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5635 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5636 return arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5637 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5638 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5639 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5640 * compile "endfor" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5641 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5642 static char_u * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5643 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
|
5644 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5645 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
|
5646 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
|
5647 forscope_T *forscope; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5648 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5649 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5650 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
|
5651 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5652 emsg(_(e_for)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5653 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5654 } |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19223
diff
changeset
|
5655 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
|
5656 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
|
5657 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
|
5658 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5659 // 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
|
5660 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
|
5661 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5662 // 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
|
5663 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
|
5664 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
|
5665 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5666 // Fill in the "end" label any BREAK statements |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5667 compile_fill_jump_to_end(&forscope->fs_end_label, cctx); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5668 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5669 // 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
|
5670 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
|
5671 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5672 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5673 vim_free(scope); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5674 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5675 return arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5676 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5677 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5678 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5679 * compile "while expr" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5680 * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5681 * Produces instructions: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5682 * 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
|
5683 * 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
|
5684 * ... body ... |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5685 * 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
|
5686 * end: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5687 * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5688 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5689 static char_u * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5690 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
|
5691 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5692 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
|
5693 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
|
5694 scope_T *scope; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5695 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5696 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
|
5697 if (scope == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5698 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5699 |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19223
diff
changeset
|
5700 scope->se_u.se_while.ws_top_label = instr->ga_len; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5701 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5702 // 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
|
5703 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
|
5704 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5705 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5706 // "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
|
5707 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
|
5708 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
|
5709 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5710 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5711 return p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5712 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5713 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5714 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5715 * compile "endwhile" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5716 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5717 static char_u * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5718 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
|
5719 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5720 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
|
5721 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5722 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
|
5723 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5724 emsg(_(e_while)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5725 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5726 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5727 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
|
5728 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
|
5729 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5730 // 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
|
5731 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
|
5732 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5733 // 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
|
5734 // And in any jumps for ":break" |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19223
diff
changeset
|
5735 compile_fill_jump_to_end(&scope->se_u.se_while.ws_end_label, cctx); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5736 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5737 vim_free(scope); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5738 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5739 return arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5740 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5741 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5742 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5743 * compile "continue" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5744 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5745 static char_u * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5746 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
|
5747 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5748 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
|
5749 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5750 for (;;) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5751 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5752 if (scope == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5753 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5754 emsg(_(e_continue)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5755 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5756 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5757 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
|
5758 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5759 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
|
5760 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5761 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5762 // Jump back to the FOR or WHILE instruction. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5763 generate_JUMP(cctx, JUMP_ALWAYS, |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19223
diff
changeset
|
5764 scope->se_type == FOR_SCOPE ? scope->se_u.se_for.fs_top_label |
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19223
diff
changeset
|
5765 : 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
|
5766 return arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5767 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5768 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5769 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5770 * compile "break" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5771 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5772 static char_u * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5773 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
|
5774 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5775 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
|
5776 endlabel_T **el; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5777 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5778 for (;;) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5779 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5780 if (scope == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5781 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5782 emsg(_(e_break)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5783 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5784 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5785 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
|
5786 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5787 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
|
5788 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5789 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5790 // 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
|
5791 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
|
5792 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
|
5793 else |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19223
diff
changeset
|
5794 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
|
5795 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
|
5796 return FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5797 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5798 return arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5799 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5800 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5801 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5802 * 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
|
5803 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5804 static char_u * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5805 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
|
5806 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5807 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
|
5808 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5809 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
|
5810 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5811 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5812 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5813 * 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
|
5814 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5815 static void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5816 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
|
5817 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5818 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
|
5819 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5820 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
|
5821 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
|
5822 vim_free(scope); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5823 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5824 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5825 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5826 * compile "try" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5827 * 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
|
5828 * finally. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5829 * 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
|
5830 * 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
|
5831 * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5832 * "try" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5833 * 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
|
5834 * ... try block |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5835 * "throw {exception}" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5836 * EVAL {exception} |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5837 * THROW create exception |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5838 * ... try block |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5839 * " catch {expr}" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5840 * JUMP -> finally |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5841 * catch1: PUSH exeception |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5842 * EVAL {expr} |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5843 * MATCH |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5844 * JUMP nomatch -> catch2 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5845 * CATCH remove exception |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5846 * ... catch block |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5847 * " catch" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5848 * JUMP -> finally |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5849 * 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
|
5850 * ... catch block |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5851 * " finally" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5852 * finally: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5853 * ... finally block |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5854 * " endtry" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5855 * 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
|
5856 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5857 static char_u * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5858 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
|
5859 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5860 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
|
5861 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
|
5862 scope_T *scope; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5863 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5864 // 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
|
5865 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
|
5866 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
|
5867 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5868 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5869 // "catch" is set when the first ":catch" is found. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5870 // "finally" is set when ":finally" or ":endtry" is found |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19223
diff
changeset
|
5871 try_scope->se_u.se_try.ts_try_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
|
5872 if (generate_instr(cctx, ISN_TRY) == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5873 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5874 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5875 // 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
|
5876 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
|
5877 if (scope == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5878 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5879 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5880 return arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5881 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5882 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5883 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5884 * compile "catch {expr}" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5885 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5886 static char_u * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5887 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
|
5888 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5889 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
|
5890 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
|
5891 char_u *p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5892 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5893 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5894 // 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
|
5895 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
|
5896 compile_endblock(cctx); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5897 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
|
5898 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5899 // 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
|
5900 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
|
5901 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5902 emsg(_(e_catch)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5903 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5904 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5905 |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19223
diff
changeset
|
5906 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
|
5907 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5908 emsg(_("E1033: catch unreachable after catch-all")); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5909 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5910 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5911 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5912 // Jump from end of previous block to :finally or :endtry |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19223
diff
changeset
|
5913 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
|
5914 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
|
5915 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5916 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5917 // End :try or :catch 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
|
5918 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_try_label; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5919 if (isn->isn_arg.try.try_catch == 0) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5920 isn->isn_arg.try.try_catch = instr->ga_len; |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19223
diff
changeset
|
5921 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
|
5922 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5923 // 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
|
5924 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_catch_label; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5925 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
|
5926 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5927 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5928 p = skipwhite(arg); |
20059
de756b3f4dee
patch 8.2.0585: Vim9: # comment not recognized after :vim9script
Bram Moolenaar <Bram@vim.org>
parents:
20055
diff
changeset
|
5929 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
|
5930 { |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19223
diff
changeset
|
5931 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
|
5932 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
|
5933 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5934 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5935 { |
19316
17dc6282f370
patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents:
19304
diff
changeset
|
5936 char_u *end; |
17dc6282f370
patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents:
19304
diff
changeset
|
5937 char_u *pat; |
17dc6282f370
patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents:
19304
diff
changeset
|
5938 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
|
5939 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
|
5940 int len; |
19316
17dc6282f370
patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents:
19304
diff
changeset
|
5941 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5942 // 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
|
5943 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
|
5944 |
19892
5feb426d2ea1
patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
19884
diff
changeset
|
5945 end = skip_regexp_ex(p + 1, *p, TRUE, &tofree, &dropped); |
19316
17dc6282f370
patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents:
19304
diff
changeset
|
5946 if (*end != *p) |
17dc6282f370
patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents:
19304
diff
changeset
|
5947 { |
17dc6282f370
patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents:
19304
diff
changeset
|
5948 semsg(_("E1067: Separator mismatch: %s"), p); |
17dc6282f370
patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents:
19304
diff
changeset
|
5949 vim_free(tofree); |
17dc6282f370
patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents:
19304
diff
changeset
|
5950 return FAIL; |
17dc6282f370
patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents:
19304
diff
changeset
|
5951 } |
17dc6282f370
patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents:
19304
diff
changeset
|
5952 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
|
5953 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
|
5954 else |
19892
5feb426d2ea1
patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
19884
diff
changeset
|
5955 len = (int)(end - tofree); |
5feb426d2ea1
patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
19884
diff
changeset
|
5956 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
|
5957 vim_free(tofree); |
19892
5feb426d2ea1
patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
19884
diff
changeset
|
5958 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
|
5959 if (pat == NULL) |
17dc6282f370
patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents:
19304
diff
changeset
|
5960 return FAIL; |
17dc6282f370
patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents:
19304
diff
changeset
|
5961 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
|
5962 return FAIL; |
17dc6282f370
patch 8.2.0216: several Vim9 instructions are not tested
Bram Moolenaar <Bram@vim.org>
parents:
19304
diff
changeset
|
5963 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5964 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
|
5965 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5966 |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19223
diff
changeset
|
5967 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
|
5968 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
|
5969 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5970 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5971 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5972 if (generate_instr(cctx, ISN_CATCH) == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5973 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5974 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5975 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
|
5976 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5977 return p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5978 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5979 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5980 static char_u * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5981 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
|
5982 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5983 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
|
5984 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
|
5985 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5986 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5987 // 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
|
5988 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
|
5989 compile_endblock(cctx); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5990 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
|
5991 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5992 // 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
|
5993 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
|
5994 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5995 emsg(_(e_finally)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5996 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5997 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5998 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5999 // 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
|
6000 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_try_label; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6001 if (isn->isn_arg.try.try_finally != 0) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6002 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6003 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
|
6004 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6005 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6006 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6007 // Fill in the "end" label in jumps at the end of the blocks. |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19223
diff
changeset
|
6008 compile_fill_jump_to_end(&scope->se_u.se_try.ts_end_label, cctx); |
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19223
diff
changeset
|
6009 |
19894
ea4f8e789627
patch 8.2.0503: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
19892
diff
changeset
|
6010 isn->isn_arg.try.try_finally = instr->ga_len; |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19223
diff
changeset
|
6011 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
|
6012 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6013 // 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
|
6014 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_catch_label; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6015 isn->isn_arg.jump.jump_where = instr->ga_len; |
21371
8e1081ede3b8
patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents:
21353
diff
changeset
|
6016 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
|
6017 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6018 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6019 // 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
|
6020 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6021 return arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6022 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6023 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6024 static char_u * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6025 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
|
6026 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6027 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
|
6028 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
|
6029 isn_T *isn; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6030 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6031 // 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
|
6032 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
|
6033 compile_endblock(cctx); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6034 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
|
6035 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6036 // 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
|
6037 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
|
6038 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6039 if (scope == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6040 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
|
6041 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
|
6042 emsg(_(e_endwhile)); |
19213
b18437efabac
patch 8.2.0165: Coverity warning for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
19193
diff
changeset
|
6043 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
|
6044 emsg(_(e_endfor)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6045 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6046 emsg(_(e_endif)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6047 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6048 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6049 |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19223
diff
changeset
|
6050 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_try_label; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6051 if (isn->isn_arg.try.try_catch == 0 && isn->isn_arg.try.try_finally == 0) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6052 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6053 emsg(_("E1032: missing :catch or :finally")); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6054 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6055 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6056 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6057 // Fill in the "end" label in jumps at the end of the blocks, if not done |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6058 // by ":finally". |
19229
d776967d0f0d
patch 8.2.0173: build fails with old compiler
Bram Moolenaar <Bram@vim.org>
parents:
19223
diff
changeset
|
6059 compile_fill_jump_to_end(&scope->se_u.se_try.ts_end_label, cctx); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6060 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6061 // End :catch or :finally scope: set value in ISN_TRY instruction |
21371
8e1081ede3b8
patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents:
21353
diff
changeset
|
6062 if (isn->isn_arg.try.try_catch == 0) |
8e1081ede3b8
patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents:
21353
diff
changeset
|
6063 isn->isn_arg.try.try_catch = 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
|
6064 if (isn->isn_arg.try.try_finally == 0) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6065 isn->isn_arg.try.try_finally = instr->ga_len; |
21371
8e1081ede3b8
patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents:
21353
diff
changeset
|
6066 |
8e1081ede3b8
patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents:
21353
diff
changeset
|
6067 if (scope->se_u.se_try.ts_catch_label != 0) |
8e1081ede3b8
patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents:
21353
diff
changeset
|
6068 { |
8e1081ede3b8
patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents:
21353
diff
changeset
|
6069 // Last catch without match jumps here |
8e1081ede3b8
patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents:
21353
diff
changeset
|
6070 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_catch_label; |
8e1081ede3b8
patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents:
21353
diff
changeset
|
6071 isn->isn_arg.jump.jump_where = instr->ga_len; |
8e1081ede3b8
patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents:
21353
diff
changeset
|
6072 } |
8e1081ede3b8
patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents:
21353
diff
changeset
|
6073 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6074 compile_endblock(cctx); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6075 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6076 if (generate_instr(cctx, ISN_ENDTRY) == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6077 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6078 return arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6079 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6080 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6081 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6082 * compile "throw {expr}" |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6083 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6084 static char_u * |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6085 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
|
6086 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6087 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
|
6088 |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
6089 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
|
6090 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6091 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
|
6092 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6093 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
|
6094 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6095 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6096 return p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6097 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6098 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6099 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6100 * 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
|
6101 * 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
|
6102 * 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
|
6103 * 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
|
6104 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6105 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
|
6106 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
|
6107 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6108 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
|
6109 int count = 0; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6110 |
19528
3b026343f398
patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents:
19521
diff
changeset
|
6111 for (;;) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6112 { |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
6113 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
|
6114 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6115 ++count; |
19528
3b026343f398
patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents:
19521
diff
changeset
|
6116 p = skipwhite(p); |
3b026343f398
patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents:
19521
diff
changeset
|
6117 if (ends_excmd(*p)) |
3b026343f398
patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents:
19521
diff
changeset
|
6118 break; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6119 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6120 |
20142
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
6121 if (cmdidx == CMD_echo || cmdidx == CMD_echon) |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
6122 generate_ECHO(cctx, cmdidx == CMD_echo, count); |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
6123 else if (cmdidx == CMD_execute) |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
6124 generate_MULT_EXPR(cctx, ISN_EXECUTE, count); |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
6125 else if (cmdidx == CMD_echomsg) |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
6126 generate_MULT_EXPR(cctx, ISN_ECHOMSG, count); |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
6127 else |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20140
diff
changeset
|
6128 generate_MULT_EXPR(cctx, ISN_ECHOERR, count); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6129 return p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6130 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6131 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6132 /* |
20170
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6133 * 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
|
6134 */ |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6135 static char_u * |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6136 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
|
6137 { |
20172
1d84eaed0ec8
patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents:
20170
diff
changeset
|
6138 char_u *p; |
20174
72b437855299
patch 8.2.0642: Vim9: using invalid index
Bram Moolenaar <Bram@vim.org>
parents:
20172
diff
changeset
|
6139 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
|
6140 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
|
6141 |
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
|
6142 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
|
6143 goto theend; |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6144 |
20174
72b437855299
patch 8.2.0642: Vim9: using invalid index
Bram Moolenaar <Bram@vim.org>
parents:
20172
diff
changeset
|
6145 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
|
6146 { |
eb6c27af07dd
patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents:
21146
diff
changeset
|
6147 long argt = excmd_get_argt(eap->cmdidx); |
eb6c27af07dd
patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents:
21146
diff
changeset
|
6148 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
|
6149 |
eb6c27af07dd
patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents:
21146
diff
changeset
|
6150 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
|
6151 |
eb6c27af07dd
patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents:
21146
diff
changeset
|
6152 // 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
|
6153 // 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
|
6154 // 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
|
6155 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
|
6156 && *eap->arg == '!') |
eb6c27af07dd
patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents:
21146
diff
changeset
|
6157 // :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
|
6158 usefilter = TRUE; |
eb6c27af07dd
patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents:
21146
diff
changeset
|
6159 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
|
6160 { |
eb6c27af07dd
patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents:
21146
diff
changeset
|
6161 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
|
6162 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
|
6163 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
|
6164 } |
eb6c27af07dd
patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents:
21146
diff
changeset
|
6165 } |
eb6c27af07dd
patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents:
21146
diff
changeset
|
6166 |
20172
1d84eaed0ec8
patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents:
20170
diff
changeset
|
6167 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
|
6168 { |
1d84eaed0ec8
patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents:
20170
diff
changeset
|
6169 // 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
|
6170 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
|
6171 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
|
6172 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
|
6173 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
|
6174 } |
1d84eaed0ec8
patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents:
20170
diff
changeset
|
6175 |
1d84eaed0ec8
patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents:
20170
diff
changeset
|
6176 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
|
6177 { |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6178 int count = 0; |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6179 char_u *start = skipwhite(line); |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6180 |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6181 // :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
|
6182 // PUSHS ":cmd xxx" |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6183 // eval expr1 |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6184 // PUSHS "yyy" |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6185 // eval expr2 |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6186 // PUSHS "zzz" |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6187 // EXECCONCAT 5 |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6188 for (;;) |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6189 { |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6190 if (p > start) |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6191 { |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20538
diff
changeset
|
6192 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
|
6193 ++count; |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6194 } |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6195 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
|
6196 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
|
6197 return NULL; |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6198 may_generate_2STRING(-1, cctx); |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6199 ++count; |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6200 p = skipwhite(p); |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6201 if (*p != '`') |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6202 { |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6203 emsg(_("E1083: missing backtick")); |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6204 return NULL; |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6205 } |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6206 start = p + 1; |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6207 |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6208 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
|
6209 if (p == NULL) |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6210 { |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6211 if (*skipwhite(start) != NUL) |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6212 { |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6213 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
|
6214 ++count; |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6215 } |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6216 break; |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6217 } |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6218 } |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6219 generate_EXECCONCAT(cctx, count); |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6220 } |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6221 else |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6222 generate_EXEC(cctx, line); |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6223 |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6224 theend: |
21156
eb6c27af07dd
patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents:
21146
diff
changeset
|
6225 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
|
6226 { |
eb6c27af07dd
patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents:
21146
diff
changeset
|
6227 // 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
|
6228 --nextcmd; |
eb6c27af07dd
patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents:
21146
diff
changeset
|
6229 *nextcmd = '|'; |
eb6c27af07dd
patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents:
21146
diff
changeset
|
6230 } |
eb6c27af07dd
patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents:
21146
diff
changeset
|
6231 |
eb6c27af07dd
patch 8.2.1129: Vim9: bar not recognized after not compiled command
Bram Moolenaar <Bram@vim.org>
parents:
21146
diff
changeset
|
6232 return nextcmd; |
20170
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6233 } |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6234 |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6235 /* |
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
|
6236 * 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
|
6237 * 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
|
6238 */ |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20419
diff
changeset
|
6239 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
|
6240 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
|
6241 { |
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
6242 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
|
6243 |
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
|
6244 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
|
6245 { |
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20933
diff
changeset
|
6246 // 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
|
6247 // 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
|
6248 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
|
6249 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
|
6250 ++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
|
6251 } |
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20933
diff
changeset
|
6252 |
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
|
6253 // 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
|
6254 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
|
6255 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
|
6256 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
|
6257 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
|
6258 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
|
6259 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
|
6260 dfunc->df_ufunc = 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
|
6261 ++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
|
6262 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
|
6263 } |
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
6264 |
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
6265 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6266 * 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
|
6267 * 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
|
6268 * Adds the function to "def_functions". |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6269 * When "set_return_type" is set then set ufunc->uf_ret_type to the type of the |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6270 * return statement (used for lambda). |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
6271 * "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
|
6272 * 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
|
6273 * "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
|
6274 * 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
|
6275 */ |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20419
diff
changeset
|
6276 int |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
6277 compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6278 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6279 char_u *line = NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6280 char_u *p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6281 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
|
6282 cctx_T cctx; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6283 garray_T *instr; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6284 int called_emsg_before = called_emsg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6285 int ret = FAIL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6286 sctx_T save_current_sctx = current_sctx; |
20538
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
6287 int do_estack_push; |
19558
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
6288 int emsg_before = called_emsg; |
21463
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
6289 int new_def_function = FALSE; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6290 |
20538
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
6291 // When using a function that was compiled before: Free old instructions. |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
6292 // 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
|
6293 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
|
6294 { |
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20336
diff
changeset
|
6295 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
|
6296 + ufunc->uf_dfunc_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
|
6297 delete_def_function_contents(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
|
6298 } |
21463
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
6299 else |
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
6300 { |
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
6301 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
|
6302 return FAIL; |
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
6303 new_def_function = TRUE; |
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
6304 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6305 |
21281
13b1567ae0c6
patch 8.2.1191: Vim9: crash when function calls itself
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
6306 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
|
6307 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
20005
diff
changeset
|
6308 CLEAR_FIELD(cctx); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6309 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
|
6310 cctx.ctx_lnum = -1; |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
6311 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
|
6312 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
|
6313 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
|
6314 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
|
6315 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
|
6316 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
|
6317 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
|
6318 |
20538
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
6319 // 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
|
6320 // 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
|
6321 // 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
|
6322 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
|
6323 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
|
6324 |
20538
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
6325 // 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
|
6326 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
|
6327 if (do_estack_push) |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
6328 estack_push_ufunc(ufunc, 1); |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
6329 |
19328
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
6330 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
|
6331 { |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
6332 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
|
6333 int first_def_arg = ufunc->uf_args.ga_len - count; |
19328
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
6334 int i; |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
6335 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
|
6336 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
|
6337 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
|
6338 |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
6339 // Produce instructions for the default values of optional arguments. |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
6340 // Store the instruction index in uf_def_arg_idx[] so that we know |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
6341 // where to start when the function is called, depending on the number |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
6342 // of arguments. |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
6343 ufunc->uf_def_arg_idx = ALLOC_CLEAR_MULT(int, count + 1); |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
6344 if (ufunc->uf_def_arg_idx == NULL) |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
6345 goto erret; |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
6346 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
|
6347 { |
19946
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
6348 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
|
6349 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
|
6350 int arg_idx = first_def_arg + i; |
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
6351 |
19328
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
6352 ufunc->uf_def_arg_idx[i] = instr->ga_len; |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
6353 arg = ((char_u **)(ufunc->uf_def_args.ga_data))[i]; |
20328
445c2b2ea44b
patch 8.2.0719: Vim9: more expressions can be evaluated at compile time
Bram Moolenaar <Bram@vim.org>
parents:
20324
diff
changeset
|
6354 if (compile_expr0(&arg, &cctx) == FAIL) |
19946
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
6355 goto erret; |
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
6356 |
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
6357 // 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
|
6358 // 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
|
6359 // specified type. |
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
6360 val_type = ((type_T **)stack->ga_data)[stack->ga_len - 1]; |
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
6361 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
|
6362 { |
4d156aead799
patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents:
21467
diff
changeset
|
6363 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
|
6364 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
|
6365 } |
21345
5dd4cbc1e9e6
patch 8.2.1223: Vim9: invalid type error for function default value
Bram Moolenaar <Bram@vim.org>
parents:
21335
diff
changeset
|
6366 else if (check_type(ufunc->uf_arg_types[arg_idx], val_type, FALSE) |
19946
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
6367 == FAIL) |
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
6368 { |
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
6369 arg_type_mismatch(ufunc->uf_arg_types[arg_idx], val_type, |
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
6370 arg_idx + 1); |
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
6371 goto erret; |
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
6372 } |
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
6373 |
8466e62a2481
patch 8.2.0529: Vim9: function argument with default not checked
Bram Moolenaar <Bram@vim.org>
parents:
19944
diff
changeset
|
6374 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
|
6375 goto erret; |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
6376 } |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
6377 ufunc->uf_def_arg_idx[count] = instr->ga_len; |
21469
4d156aead799
patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents:
21467
diff
changeset
|
6378 |
4d156aead799
patch 8.2.1285: Vim9: argument types are not checked on assignment
Bram Moolenaar <Bram@vim.org>
parents:
21467
diff
changeset
|
6379 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
|
6380 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
|
6381 } |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
6382 |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
6383 /* |
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19316
diff
changeset
|
6384 * 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
|
6385 */ |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6386 for (;;) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6387 { |
21689
10866fd07595
patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents:
21683
diff
changeset
|
6388 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
|
6389 cmdmod_T save_cmdmod; |
10866fd07595
patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents:
21683
diff
changeset
|
6390 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
|
6391 char_u *cmd; |
10866fd07595
patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents:
21683
diff
changeset
|
6392 int save_msg_scroll = msg_scroll; |
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
|
6393 |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
6394 // 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
|
6395 // the right line number when inside try/catch. |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
6396 if (emsg_before != called_emsg) |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
6397 goto erret; |
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19904
diff
changeset
|
6398 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6399 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
|
6400 // 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
|
6401 ++line; |
20949
62912ad41aff
patch 8.2.1026: Vim9: cannot break the line after "->"
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
6402 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
|
6403 && !(*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
|
6404 || 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
|
6405 { |
21455
8cc1555f2445
patch 8.2.1278: Vim9: line break after "->" only allowed in :def function
Bram Moolenaar <Bram@vim.org>
parents:
21443
diff
changeset
|
6406 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
|
6407 goto erret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6408 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6409 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6410 { |
20955
396fe712eb0f
patch 8.2.1029: Vim9: cannot chain function calls with -> at line start
Bram Moolenaar <Bram@vim.org>
parents:
20953
diff
changeset
|
6411 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
|
6412 if (cctx.ctx_lnum >= ufunc->uf_lines.ga_len) |
20055
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6413 // beyond the last line |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6414 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6415 } |
19558
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
6416 emsg_before = called_emsg; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6417 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
20005
diff
changeset
|
6418 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
|
6419 ea.cmdlinep = &line; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6420 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
|
6421 |
20055
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6422 // 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
|
6423 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
|
6424 { |
20055
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6425 case '#': |
20170
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6426 // "#" starts a comment, but "#{" does not. |
20055
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6427 if (ea.cmd[1] != '{') |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6428 { |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6429 line = (char_u *)""; |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6430 continue; |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6431 } |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6432 break; |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6433 |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6434 case '}': |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6435 { |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6436 // "}" 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
|
6437 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
|
6438 ? 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
|
6439 |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6440 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
|
6441 { |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6442 compile_endblock(&cctx); |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6443 line = ea.cmd; |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6444 } |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6445 else |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6446 { |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6447 emsg(_("E1025: using } outside of a block scope")); |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6448 goto erret; |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6449 } |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6450 if (line != NULL) |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6451 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
|
6452 continue; |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6453 } |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6454 |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6455 case '{': |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6456 // "{" 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
|
6457 // "{'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
|
6458 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
|
6459 { |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6460 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
|
6461 continue; |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6462 } |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6463 break; |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6464 |
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6465 case ':': |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
6466 starts_with_colon = TRUE; |
20055
686deb5959c2
patch 8.2.0583: Vim9: # comment not recognized in :def function
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
6467 break; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6468 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6469 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6470 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6471 * COMMAND MODIFIERS |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6472 */ |
21689
10866fd07595
patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents:
21683
diff
changeset
|
6473 save_cmdmod = cmdmod; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6474 if (parse_command_modifiers(&ea, &errormsg, FALSE) == FAIL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6475 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6476 if (errormsg != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6477 goto erret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6478 // 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
|
6479 line = (char_u *)""; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6480 continue; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6481 } |
21172
96ae8622cfb6
patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents:
21160
diff
changeset
|
6482 // TODO: use modifiers in the command |
96ae8622cfb6
patch 8.2.1137: Vim9: modifiers not cleared after compiling function
Bram Moolenaar <Bram@vim.org>
parents:
21160
diff
changeset
|
6483 undo_cmdmod(&ea, save_msg_scroll); |
21689
10866fd07595
patch 8.2.1394: Vim9: compiling a function interferes with command modifiers
Bram Moolenaar <Bram@vim.org>
parents:
21683
diff
changeset
|
6484 cmdmod = save_cmdmod; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6485 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6486 // Skip ":call" to get to the function name. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6487 if (checkforcmd(&ea.cmd, "call", 3)) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6488 ea.cmd = skipwhite(ea.cmd); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6489 |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
6490 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
|
6491 { |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
6492 char_u *pskip; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
6493 |
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
|
6494 // Assuming the command starts with a variable or function name, |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
6495 // find what follows. |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
6496 // Skip over "var.member", "var[idx]" and the like. |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
6497 // Also "&opt = val", "$ENV = val" and "@r = val". |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
6498 pskip = (*ea.cmd == '&' || *ea.cmd == '$' || *ea.cmd == '@') |
19473
b09afbebffee
patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents:
19467
diff
changeset
|
6499 ? ea.cmd + 1 : ea.cmd; |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
6500 p = to_name_end(pskip, TRUE); |
19862
846fbbacce3a
patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19860
diff
changeset
|
6501 if (p > ea.cmd && *p != NUL) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6502 { |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
6503 char_u *var_end; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
6504 int oplen; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
6505 int heredoc; |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
6506 |
21614
d0128ecd4341
patch 8.2.1357: Vim9: cannot assign to / register
Bram Moolenaar <Bram@vim.org>
parents:
21612
diff
changeset
|
6507 if (ea.cmd[0] == '@') |
d0128ecd4341
patch 8.2.1357: Vim9: cannot assign to / register
Bram Moolenaar <Bram@vim.org>
parents:
21612
diff
changeset
|
6508 var_end = ea.cmd + 2; |
d0128ecd4341
patch 8.2.1357: Vim9: cannot assign to / register
Bram Moolenaar <Bram@vim.org>
parents:
21612
diff
changeset
|
6509 else |
d0128ecd4341
patch 8.2.1357: Vim9: cannot assign to / register
Bram Moolenaar <Bram@vim.org>
parents:
21612
diff
changeset
|
6510 var_end = find_name_end(pskip, NULL, NULL, |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
6511 FNE_CHECK_START | FNE_INCL_BR); |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
6512 oplen = assignment_len(skipwhite(var_end), &heredoc); |
19473
b09afbebffee
patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents:
19467
diff
changeset
|
6513 if (oplen > 0) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6514 { |
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
|
6515 size_t len = p - ea.cmd; |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20349
diff
changeset
|
6516 |
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
|
6517 // Recognize an assignment if we recognize the variable |
b09afbebffee
patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents:
19467
diff
changeset
|
6518 // name: |
b09afbebffee
patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents:
19467
diff
changeset
|
6519 // "g:var = expr" |
19583
ba35daca6553
patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents:
19579
diff
changeset
|
6520 // "local = expr" where "local" is a local var. |
ba35daca6553
patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents:
19579
diff
changeset
|
6521 // "script = expr" where "script" is a script-local var. |
ba35daca6553
patch 8.2.0348: Vim9: not all code tested
Bram Moolenaar <Bram@vim.org>
parents:
19579
diff
changeset
|
6522 // "import = expr" where "import" is an imported var |
19473
b09afbebffee
patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents:
19467
diff
changeset
|
6523 // "&opt = expr" |
b09afbebffee
patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents:
19467
diff
changeset
|
6524 // "$ENV = expr" |
b09afbebffee
patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents:
19467
diff
changeset
|
6525 // "@r = expr" |
b09afbebffee
patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents:
19467
diff
changeset
|
6526 if (*ea.cmd == '&' |
b09afbebffee
patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents:
19467
diff
changeset
|
6527 || *ea.cmd == '$' |
b09afbebffee
patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents:
19467
diff
changeset
|
6528 || *ea.cmd == '@' |
20355
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20349
diff
changeset
|
6529 || ((len) > 2 && ea.cmd[1] == ':') |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20349
diff
changeset
|
6530 || lookup_local(ea.cmd, len, &cctx) != NULL |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20349
diff
changeset
|
6531 || lookup_arg(ea.cmd, len, NULL, NULL, |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20349
diff
changeset
|
6532 NULL, &cctx) == OK |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20349
diff
changeset
|
6533 || lookup_script(ea.cmd, len) == OK |
fc2d76e0994c
patch 8.2.0733: Vim9: assigning to dict or list argument does not work
Bram Moolenaar <Bram@vim.org>
parents:
20349
diff
changeset
|
6534 || find_imported(ea.cmd, len, &cctx) != NULL) |
19473
b09afbebffee
patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents:
19467
diff
changeset
|
6535 { |
b09afbebffee
patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents:
19467
diff
changeset
|
6536 line = compile_assignment(ea.cmd, &ea, CMD_SIZE, &cctx); |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
6537 if (line == NULL || line == ea.cmd) |
19473
b09afbebffee
patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents:
19467
diff
changeset
|
6538 goto erret; |
b09afbebffee
patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents:
19467
diff
changeset
|
6539 continue; |
b09afbebffee
patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents:
19467
diff
changeset
|
6540 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6541 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6542 } |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
6543 |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
6544 if (*ea.cmd == '[') |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
6545 { |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
6546 // [var, var] = expr |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
6547 line = compile_assignment(ea.cmd, &ea, CMD_SIZE, &cctx); |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
6548 if (line == NULL) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
6549 goto erret; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
6550 if (line != ea.cmd) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
6551 continue; |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
6552 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6553 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6554 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6555 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6556 * COMMAND after range |
21335
af3663df42bf
patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents:
21301
diff
changeset
|
6557 * '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
|
6558 */ |
20982
bb49b5090a9c
patch 8.2.1042: Vim9: cannot put an operator on the next line
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
6559 cmd = ea.cmd; |
21335
af3663df42bf
patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents:
21301
diff
changeset
|
6560 if (*cmd != '\'') |
20982
bb49b5090a9c
patch 8.2.1042: Vim9: cannot put an operator on the next line
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
6561 { |
21335
af3663df42bf
patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents:
21301
diff
changeset
|
6562 ea.cmd = skip_range(ea.cmd, NULL); |
af3663df42bf
patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents:
21301
diff
changeset
|
6563 if (ea.cmd > cmd && !starts_with_colon) |
af3663df42bf
patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents:
21301
diff
changeset
|
6564 { |
af3663df42bf
patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents:
21301
diff
changeset
|
6565 emsg(_(e_colon_required)); |
af3663df42bf
patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents:
21301
diff
changeset
|
6566 goto erret; |
af3663df42bf
patch 8.2.1218: Vim9: cannot use 'text'->func()
Bram Moolenaar <Bram@vim.org>
parents:
21301
diff
changeset
|
6567 } |
20982
bb49b5090a9c
patch 8.2.1042: Vim9: cannot put an operator on the next line
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
6568 } |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
6569 p = find_ex_command(&ea, NULL, starts_with_colon ? NULL |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
6570 : (void *(*)(char_u *, size_t, cctx_T *))lookup_local, |
19473
b09afbebffee
patch 8.2.0294: cannot use Ex command that is also a function name
Bram Moolenaar <Bram@vim.org>
parents:
19467
diff
changeset
|
6571 &cctx); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6572 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6573 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
|
6574 { |
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
|
6575 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
|
6576 { |
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
6577 line += STRLEN(line); |
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
6578 continue; |
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
6579 } |
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
6580 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6581 // 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
|
6582 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
|
6583 { |
21196
f45ce1ce284c
patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21194
diff
changeset
|
6584 // CMD_let cannot happen, compile_assignment() above is used |
f45ce1ce284c
patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21194
diff
changeset
|
6585 iemsg("Command from find_ex_command() not handled"); |
f45ce1ce284c
patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21194
diff
changeset
|
6586 goto erret; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6587 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6588 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6589 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6590 p = skipwhite(p); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6591 |
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
|
6592 if (cctx.ctx_skip == SKIP_YES |
20929
808e39c257de
patch 8.2.1016: Vim9: test fails when channel feature is missing
Bram Moolenaar <Bram@vim.org>
parents:
20909
diff
changeset
|
6593 && ea.cmdidx != CMD_if |
19253
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
6594 && 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
|
6595 && ea.cmdidx != CMD_else |
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
6596 && ea.cmdidx != CMD_endif) |
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
6597 { |
20170
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6598 line = (char_u *)""; |
19253
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
6599 continue; |
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
6600 } |
a8d2d3c8f0b3
patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents:
19229
diff
changeset
|
6601 |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
6602 if (ea.cmdidx != CMD_elseif |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
6603 && ea.cmdidx != CMD_else |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
6604 && ea.cmdidx != CMD_endif |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
6605 && ea.cmdidx != CMD_endfor |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
6606 && ea.cmdidx != CMD_endwhile |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
6607 && ea.cmdidx != CMD_catch |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
6608 && ea.cmdidx != CMD_finally |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
6609 && ea.cmdidx != CMD_endtry) |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
6610 { |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
6611 if (cctx.ctx_had_return) |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
6612 { |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
6613 emsg(_("E1095: Unreachable code after :return")); |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
6614 goto erret; |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
6615 } |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
6616 } |
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
6617 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6618 switch (ea.cmdidx) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6619 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6620 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
|
6621 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
|
6622 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
|
6623 break; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
6624 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6625 case CMD_function: |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20275
diff
changeset
|
6626 emsg(_("E1086: 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
|
6627 goto erret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6628 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6629 case CMD_return: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6630 line = compile_return(p, set_return_type, &cctx); |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
6631 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
|
6632 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6633 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6634 case CMD_let: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6635 case CMD_const: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6636 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
|
6637 if (line == p) |
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
6638 line = NULL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6639 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6640 |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
6641 case CMD_unlet: |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
6642 case CMD_unlockvar: |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
6643 case CMD_lockvar: |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
6644 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
|
6645 break; |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
6646 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6647 case CMD_import: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6648 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
|
6649 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6650 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6651 case CMD_if: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6652 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
|
6653 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6654 case CMD_elseif: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6655 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
|
6656 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
|
6657 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6658 case CMD_else: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6659 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
|
6660 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
|
6661 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6662 case CMD_endif: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6663 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
|
6664 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6665 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6666 case CMD_while: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6667 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
|
6668 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6669 case CMD_endwhile: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6670 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
|
6671 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
|
6672 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6673 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6674 case CMD_for: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6675 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
|
6676 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6677 case CMD_endfor: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6678 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
|
6679 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
|
6680 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6681 case CMD_continue: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6682 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
|
6683 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6684 case CMD_break: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6685 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
|
6686 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6687 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6688 case CMD_try: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6689 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
|
6690 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6691 case CMD_catch: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6692 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
|
6693 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
|
6694 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6695 case CMD_finally: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6696 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
|
6697 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
|
6698 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6699 case CMD_endtry: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6700 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
|
6701 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
|
6702 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6703 case CMD_throw: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6704 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
|
6705 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6706 |
21196
f45ce1ce284c
patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21194
diff
changeset
|
6707 case CMD_eval: |
f45ce1ce284c
patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21194
diff
changeset
|
6708 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
|
6709 goto erret; |
f45ce1ce284c
patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21194
diff
changeset
|
6710 |
f45ce1ce284c
patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21194
diff
changeset
|
6711 // drop the return value |
f45ce1ce284c
patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21194
diff
changeset
|
6712 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
|
6713 |
f45ce1ce284c
patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21194
diff
changeset
|
6714 line = skipwhite(p); |
f45ce1ce284c
patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21194
diff
changeset
|
6715 break; |
f45ce1ce284c
patch 8.2.1149: Vim9: :eval command not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
21194
diff
changeset
|
6716 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6717 case CMD_echo: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6718 case CMD_echon: |
19528
3b026343f398
patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents:
19521
diff
changeset
|
6719 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
|
6720 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
|
6721 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
|
6722 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
|
6723 break; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6724 |
20982
bb49b5090a9c
patch 8.2.1042: Vim9: cannot put an operator on the next line
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
6725 // TODO: other commands with an expression argument |
bb49b5090a9c
patch 8.2.1042: Vim9: cannot put an operator on the next line
Bram Moolenaar <Bram@vim.org>
parents:
20972
diff
changeset
|
6726 |
21516
c7b2ce90c2de
patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents:
21512
diff
changeset
|
6727 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
|
6728 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
|
6729 case CMD_insert: |
21584
d0c76ce48326
patch 8.2.1342: Vim9: accidentally using "t" gives a confusing error
Bram Moolenaar <Bram@vim.org>
parents:
21578
diff
changeset
|
6730 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
|
6731 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
|
6732 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
|
6733 goto erret; |
c7b2ce90c2de
patch 8.2.1308: Vim9: accidentally using "x" causes Vim to exit
Bram Moolenaar <Bram@vim.org>
parents:
21512
diff
changeset
|
6734 |
21210
44611891e22c
patch 8.2.1156: Vim9: No error for invalid command in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
6735 case CMD_SIZE: |
44611891e22c
patch 8.2.1156: Vim9: No error for invalid command in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
6736 semsg(_("E476: Invalid command: %s"), ea.cmd); |
44611891e22c
patch 8.2.1156: Vim9: No error for invalid command in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
6737 goto erret; |
44611891e22c
patch 8.2.1156: Vim9: No error for invalid command in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
21208
diff
changeset
|
6738 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6739 default: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6740 // Not recognized, execute with do_cmdline_cmd(). |
20170
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6741 ea.arg = p; |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6742 line = compile_exec(line, &ea, &cctx); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6743 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6744 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6745 if (line == NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6746 goto erret; |
19894
ea4f8e789627
patch 8.2.0503: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
19892
diff
changeset
|
6747 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
|
6748 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6749 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
|
6750 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6751 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
|
6752 goto erret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6753 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6754 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6755 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6756 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
|
6757 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6758 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
|
6759 emsg(_(e_endif)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6760 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
|
6761 emsg(_(e_endwhile)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6762 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
|
6763 emsg(_(e_endfor)); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6764 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6765 emsg(_("E1026: Missing }")); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6766 goto erret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6767 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6768 |
20909
0d7465881b06
patch 8.2.1006: Vim9: require unnecessary return statement
Bram Moolenaar <Bram@vim.org>
parents:
20907
diff
changeset
|
6769 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
|
6770 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6771 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
|
6772 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6773 emsg(_("E1027: Missing return statement")); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6774 goto erret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6775 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6776 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6777 // Return zero if there is no return at the end. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6778 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
|
6779 generate_instr(&cctx, ISN_RETURN); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6780 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6781 |
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
|
6782 { |
8288884fdfe1
patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents:
19862
diff
changeset
|
6783 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
|
6784 + 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
|
6785 dfunc->df_deleted = FALSE; |
8288884fdfe1
patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents:
19862
diff
changeset
|
6786 dfunc->df_instr = instr->ga_data; |
8288884fdfe1
patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents:
19862
diff
changeset
|
6787 dfunc->df_instr_count = instr->ga_len; |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
6788 dfunc->df_varcount = cctx.ctx_locals_count; |
20247
e46e72aaff74
patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20244
diff
changeset
|
6789 dfunc->df_closure_count = cctx.ctx_closure_count; |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
6790 if (cctx.ctx_outer_used) |
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
6791 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
|
6792 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
|
6793 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6794 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6795 ret = OK; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6796 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6797 erret: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6798 if (ret == FAIL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6799 { |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
6800 int idx; |
19864
8288884fdfe1
patch 8.2.0488: Vim9: compiling can break when using a lambda inside :def
Bram Moolenaar <Bram@vim.org>
parents:
19862
diff
changeset
|
6801 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
|
6802 + 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
|
6803 |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
6804 for (idx = 0; idx < instr->ga_len; ++idx) |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
6805 delete_instr(((isn_T *)instr->ga_data) + idx); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6806 ga_clear(instr); |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
6807 |
21463
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
6808 // 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
|
6809 // might as well remove it. |
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
6810 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
|
6811 && 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
|
6812 { |
20534
ae758aa4ee5e
patch 8.2.0821: Vim9: memory leak in expr test
Bram Moolenaar <Bram@vim.org>
parents:
20532
diff
changeset
|
6813 --def_functions.ga_len; |
21463
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
6814 ufunc->uf_dfunc_idx = 0; |
7f36d36f7195
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Bram Moolenaar <Bram@vim.org>
parents:
21455
diff
changeset
|
6815 } |
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
|
6816 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
|
6817 |
19896
92177b596695
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
19894
diff
changeset
|
6818 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
|
6819 drop_scope(&cctx); |
92177b596695
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Bram Moolenaar <Bram@vim.org>
parents:
19894
diff
changeset
|
6820 |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
6821 // Don't execute this function body. |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
6822 ga_clear_strings(&ufunc->uf_lines); |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
6823 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6824 if (errormsg != NULL) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6825 emsg(errormsg); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6826 else if (called_emsg == called_emsg_before) |
19411
bc880a130120
patch 8.2.0263: a few new Vim9 messages are not localized
Bram Moolenaar <Bram@vim.org>
parents:
19392
diff
changeset
|
6827 emsg(_("E1028: compile_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
|
6828 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6829 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6830 current_sctx = save_current_sctx; |
20538
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
6831 if (do_estack_push) |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
6832 estack_pop(); |
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20534
diff
changeset
|
6833 |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
6834 free_imported(&cctx); |
20239
2135b4641680
patch 8.2.0675: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20207
diff
changeset
|
6835 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
|
6836 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
|
6837 return ret; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6838 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6839 |
20532
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
6840 void |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
6841 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
|
6842 { |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
6843 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
|
6844 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
|
6845 |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
6846 // 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
|
6847 // argument types. |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
6848 // 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
|
6849 // 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
|
6850 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
|
6851 { |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
6852 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
|
6853 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
|
6854 // 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
|
6855 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
|
6856 argcount + varargs, |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
6857 &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
|
6858 return; |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
6859 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
|
6860 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
|
6861 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
|
6862 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
|
6863 { |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
6864 int i; |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
6865 |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
6866 // 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
|
6867 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
|
6868 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
|
6869 } |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
6870 else |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
6871 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
|
6872 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
|
6873 if (varargs) |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
6874 { |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
6875 ufunc->uf_func_type->tt_args[argcount] = |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
6876 ufunc->uf_va_type == NULL ? &t_any : ufunc->uf_va_type; |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
6877 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
|
6878 } |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
6879 } |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
6880 else |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
6881 // 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
|
6882 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
|
6883 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
|
6884 } |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
6885 |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
6886 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6887 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6888 * 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
|
6889 */ |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
6890 void |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6891 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
|
6892 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6893 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
|
6894 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6895 case ISN_EXEC: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6896 case ISN_LOADENV: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6897 case ISN_LOADG: |
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
|
6898 case ISN_LOADB: |
7fc5d62fe2a5
patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents:
20079
diff
changeset
|
6899 case ISN_LOADW: |
7fc5d62fe2a5
patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents:
20079
diff
changeset
|
6900 case ISN_LOADT: |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6901 case ISN_LOADOPT: |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
6902 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
|
6903 case ISN_PUSHEXC: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6904 case ISN_PUSHS: |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
6905 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
|
6906 case ISN_STOREG: |
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
|
6907 case ISN_STOREB: |
7fc5d62fe2a5
patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents:
20079
diff
changeset
|
6908 case ISN_STOREW: |
7fc5d62fe2a5
patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents:
20079
diff
changeset
|
6909 case ISN_STORET: |
19558
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
6910 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
|
6911 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
|
6912 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6913 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6914 case ISN_LOADS: |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
6915 case ISN_STORES: |
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
6916 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
|
6917 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6918 |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
6919 case ISN_UNLET: |
20099
058b41f85bcb
patch 8.2.0605: Vim9: cannot unlet an environment variable
Bram Moolenaar <Bram@vim.org>
parents:
20091
diff
changeset
|
6920 case ISN_UNLETENV: |
20091
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
6921 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
|
6922 break; |
a64c16ff98b8
patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents:
20089
diff
changeset
|
6923 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6924 case ISN_STOREOPT: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6925 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
|
6926 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6927 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6928 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
|
6929 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
|
6930 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6931 |
19558
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
6932 case ISN_PUSHJOB: |
19562
6b7719b8f9b9
patch 8.2.0338: build failure without the channel feature
Bram Moolenaar <Bram@vim.org>
parents:
19558
diff
changeset
|
6933 #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
|
6934 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
|
6935 #endif |
19558
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
6936 break; |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
6937 |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
6938 case ISN_PUSHCHANNEL: |
19562
6b7719b8f9b9
patch 8.2.0338: build failure without the channel feature
Bram Moolenaar <Bram@vim.org>
parents:
19558
diff
changeset
|
6939 #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
|
6940 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
|
6941 #endif |
19558
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
6942 break; |
8eeec8886c02
patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents:
19530
diff
changeset
|
6943 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6944 case ISN_UCALL: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6945 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
|
6946 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6947 |
20283
934657e365e5
patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
6948 case ISN_FUNCREF: |
934657e365e5
patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
6949 { |
934657e365e5
patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
6950 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
|
6951 + isn->isn_arg.funcref.fr_func; |
934657e365e5
patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
6952 func_ptr_unref(dfunc->df_ufunc); |
934657e365e5
patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
6953 } |
934657e365e5
patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
6954 break; |
934657e365e5
patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents:
20281
diff
changeset
|
6955 |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
6956 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
|
6957 { |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21562
diff
changeset
|
6958 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
|
6959 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
|
6960 |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21562
diff
changeset
|
6961 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
|
6962 { |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21562
diff
changeset
|
6963 // Clear uf_dfunc_idx so that the function is deleted. |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21562
diff
changeset
|
6964 clear_def_function(ufunc); |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21562
diff
changeset
|
6965 ufunc->uf_dfunc_idx = 0; |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21562
diff
changeset
|
6966 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
|
6967 } |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21562
diff
changeset
|
6968 |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21562
diff
changeset
|
6969 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
|
6970 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
|
6971 } |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
6972 break; |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21546
diff
changeset
|
6973 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6974 case ISN_2BOOL: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6975 case ISN_2STRING: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6976 case ISN_ADDBLOB: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6977 case ISN_ADDLIST: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6978 case ISN_BCALL: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6979 case ISN_CATCH: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6980 case ISN_CHECKNR: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6981 case ISN_CHECKTYPE: |
20871
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
6982 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
|
6983 case ISN_COMPAREANY: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6984 case ISN_COMPAREBLOB: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6985 case ISN_COMPAREBOOL: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6986 case ISN_COMPAREDICT: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6987 case ISN_COMPAREFLOAT: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6988 case ISN_COMPAREFUNC: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6989 case ISN_COMPARELIST: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6990 case ISN_COMPARENR: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6991 case ISN_COMPARESPECIAL: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6992 case ISN_COMPARESTRING: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6993 case ISN_CONCAT: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6994 case ISN_DCALL: |
21232
3f14e0d4a4dd
patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents:
21220
diff
changeset
|
6995 case ISN_SHUFFLE: |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6996 case ISN_DROP: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6997 case ISN_ECHO: |
20170
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
6998 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
|
6999 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
|
7000 case ISN_ENDTRY: |
20170
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
7001 case ISN_EXECCONCAT: |
0612c64a2b87
patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
20142
diff
changeset
|
7002 case ISN_EXECUTE: |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7003 case ISN_FOR: |
21393
320581a133d9
patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents:
21391
diff
changeset
|
7004 case ISN_LISTINDEX: |
320581a133d9
patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents:
21391
diff
changeset
|
7005 case ISN_STRINDEX: |
20859
876e16c48bd1
patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents:
20842
diff
changeset
|
7006 case ISN_GETITEM: |
20871
65d9189d4dca
patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents:
20859
diff
changeset
|
7007 case ISN_SLICE: |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
7008 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
|
7009 case ISN_JUMP: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7010 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
|
7011 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
|
7012 case ISN_LOADGDICT: |
20244
23d75968ca5e
patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents:
20239
diff
changeset
|
7013 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
|
7014 case ISN_LOADREG: |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7015 case ISN_LOADSCRIPT: |
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
|
7016 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
|
7017 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
|
7018 case ISN_LOADWDICT: |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7019 case ISN_NEGATENR: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7020 case ISN_NEWDICT: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7021 case ISN_NEWLIST: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7022 case ISN_OPNR: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7023 case ISN_OPFLOAT: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7024 case ISN_OPANY: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7025 case ISN_PCALL: |
19862
846fbbacce3a
patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19860
diff
changeset
|
7026 case ISN_PCALL_END: |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7027 case ISN_PUSHF: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7028 case ISN_PUSHNR: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7029 case ISN_PUSHBOOL: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7030 case ISN_PUSHSPEC: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7031 case ISN_RETURN: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7032 case ISN_STORE: |
20295
bc2c9ea94ec1
patch 8.2.0703: Vim9: closure cannot store value in outer context
Bram Moolenaar <Bram@vim.org>
parents:
20283
diff
changeset
|
7033 case ISN_STOREOUTER: |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
7034 case ISN_STOREV: |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7035 case ISN_STORENR: |
19283
9dc843109c97
patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19259
diff
changeset
|
7036 case ISN_STOREREG: |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7037 case ISN_STORESCRIPT: |
20349
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
7038 case ISN_STOREDICT: |
e29b2ec8d4d2
patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
7039 case ISN_STORELIST: |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7040 case ISN_THROW: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7041 case ISN_TRY: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7042 // nothing allocated |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7043 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7044 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7045 } |
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 /* |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7048 * Free all instructions for "dfunc". |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7049 */ |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7050 static void |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7051 delete_def_function_contents(dfunc_T *dfunc) |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7052 { |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7053 int idx; |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7054 |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7055 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
|
7056 |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7057 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
|
7058 { |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7059 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
|
7060 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
|
7061 VIM_CLEAR(dfunc->df_instr); |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7062 } |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7063 |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7064 dfunc->df_deleted = TRUE; |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7065 } |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7066 |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7067 /* |
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
|
7068 * When a user function is deleted, clear the contents of any associated def |
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20933
diff
changeset
|
7069 * function. 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
|
7070 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7071 void |
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
|
7072 clear_def_function(ufunc_T *ufunc) |
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20933
diff
changeset
|
7073 { |
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20933
diff
changeset
|
7074 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
|
7075 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7076 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
|
7077 + 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
|
7078 |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7079 delete_def_function_contents(dfunc); |
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
|
7080 ufunc->uf_def_status = UF_NOT_COMPILED; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7081 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7082 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7083 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7084 #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
|
7085 /* |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7086 * 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
|
7087 */ |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7088 void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7089 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
|
7090 { |
19726
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7091 int idx; |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7092 |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7093 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
|
7094 { |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7095 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
|
7096 |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7097 delete_def_function_contents(dfunc); |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7098 } |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7099 |
ad37a198a708
patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents:
19623
diff
changeset
|
7100 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
|
7101 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7102 #endif |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7103 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7104 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7105 #endif // FEAT_EVAL |