annotate src/vim9cmds.c @ 30065:6cf788ab844c v9.0.0370

patch 9.0.0370: cleaning up afterwards can make a function messy Commit: https://github.com/vim/vim/commit/1d84f7608f1e41dad03b8cc7925895437775f7c0 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Sep 3 21:35:53 2022 +0100 patch 9.0.0370: cleaning up afterwards can make a function messy Problem: Cleaning up afterwards can make a function messy. Solution: Add the :defer command.
author Bram Moolenaar <Bram@vim.org>
date Sat, 03 Sep 2022 22:45:03 +0200
parents d269dd3cd31d
children a542dfb1c1a2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * vim9cmds.c: Dealing with commands of a compiled function
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #define USING_FLOAT_STUFF
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 #include "vim.h"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 #if defined(FEAT_EVAL) || defined(PROTO)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 // When not generating protos this is included in proto.h
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 #ifdef PROTO
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 # include "vim9.h"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 #endif
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 * Get the index of the current instruction.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 * This compensates for a preceding ISN_CMDMOD and ISN_PROF_START.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 static int
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 current_instr_idx(cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 garray_T *instr = &cctx->ctx_instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 int idx = instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 while (idx > 0)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 if (cctx->ctx_has_cmdmod && ((isn_T *)instr->ga_data)[idx - 1]
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 .isn_type == ISN_CMDMOD)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 --idx;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 continue;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 #ifdef FEAT_PROFILE
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 if (((isn_T *)instr->ga_data)[idx - 1].isn_type == ISN_PROF_START)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 --idx;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 continue;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 #endif
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 if (((isn_T *)instr->ga_data)[idx - 1].isn_type == ISN_DEBUG)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 --idx;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 continue;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 break;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 return idx;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 * Remove local variables above "new_top".
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 static void
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 unwind_locals(cctx_T *cctx, int new_top)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 if (cctx->ctx_locals.ga_len > new_top)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 int idx;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 lvar_T *lvar;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 for (idx = new_top; idx < cctx->ctx_locals.ga_len; ++idx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 lvar = ((lvar_T *)cctx->ctx_locals.ga_data) + idx;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 vim_free(lvar->lv_name);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 cctx->ctx_locals.ga_len = new_top;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 * Free all local variables.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 void
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 free_locals(cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 unwind_locals(cctx, 0);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 ga_clear(&cctx->ctx_locals);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 * Check if "name" can be "unlet".
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 int
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 check_vim9_unlet(char_u *name)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 {
29744
1e9ee1b61d6d patch 9.0.0212: invalid memory access when compiling :unlet
Bram Moolenaar <Bram@vim.org>
parents: 29742
diff changeset
95 if (*name == NUL)
1e9ee1b61d6d patch 9.0.0212: invalid memory access when compiling :unlet
Bram Moolenaar <Bram@vim.org>
parents: 29742
diff changeset
96 {
1e9ee1b61d6d patch 9.0.0212: invalid memory access when compiling :unlet
Bram Moolenaar <Bram@vim.org>
parents: 29742
diff changeset
97 semsg(_(e_argument_required_for_str), "unlet");
1e9ee1b61d6d patch 9.0.0212: invalid memory access when compiling :unlet
Bram Moolenaar <Bram@vim.org>
parents: 29742
diff changeset
98 return FAIL;
1e9ee1b61d6d patch 9.0.0212: invalid memory access when compiling :unlet
Bram Moolenaar <Bram@vim.org>
parents: 29742
diff changeset
99 }
1e9ee1b61d6d patch 9.0.0212: invalid memory access when compiling :unlet
Bram Moolenaar <Bram@vim.org>
parents: 29742
diff changeset
100
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 if (name[1] != ':' || vim_strchr((char_u *)"gwtb", *name) == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 // "unlet s:var" is allowed in legacy script.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 if (*name == 's' && !script_is_vim9())
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 return OK;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 semsg(_(e_cannot_unlet_str), name);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 return FAIL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 return OK;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 * Callback passed to ex_unletlock().
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 static int
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 compile_unlet(
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 lval_T *lvp,
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 char_u *name_end,
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 exarg_T *eap,
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 int deep UNUSED,
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 void *coookie)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 cctx_T *cctx = coookie;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 char_u *p = lvp->ll_name;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 int cc = *name_end;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 int ret = OK;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 if (cctx->ctx_skip == SKIP_YES)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 return OK;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 *name_end = NUL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 if (*p == '$')
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 // :unlet $ENV_VAR
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 ret = generate_UNLET(cctx, ISN_UNLETENV, p + 1, eap->forceit);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 else if (vim_strchr(p, '.') != NULL || vim_strchr(p, '[') != NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 lhs_T lhs;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 // This is similar to assigning: lookup the list/dict, compile the
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 // idx/key. Then instead of storing the value unlet the item.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 // unlet {list}[idx]
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 // unlet {dict}[key] dict.key
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 //
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 // Figure out the LHS type and other properties.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 //
28281
bd1dcc605e58 patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 28179
diff changeset
148 ret = compile_lhs(p, &lhs, CMD_unlet, FALSE, FALSE, 0, cctx);
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149
26984
8dc4782b60ff patch 8.2.4021: missing part of the :import changes
Bram Moolenaar <Bram@vim.org>
parents: 26935
diff changeset
150 // Use the info in "lhs" to unlet the item at the index in the
8dc4782b60ff patch 8.2.4021: missing part of the :import changes
Bram Moolenaar <Bram@vim.org>
parents: 26935
diff changeset
151 // list or dict.
8dc4782b60ff patch 8.2.4021: missing part of the :import changes
Bram Moolenaar <Bram@vim.org>
parents: 26935
diff changeset
152 if (ret == OK)
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 {
26984
8dc4782b60ff patch 8.2.4021: missing part of the :import changes
Bram Moolenaar <Bram@vim.org>
parents: 26935
diff changeset
154 if (!lhs.lhs_has_index)
8dc4782b60ff patch 8.2.4021: missing part of the :import changes
Bram Moolenaar <Bram@vim.org>
parents: 26935
diff changeset
155 {
8dc4782b60ff patch 8.2.4021: missing part of the :import changes
Bram Moolenaar <Bram@vim.org>
parents: 26935
diff changeset
156 semsg(_(e_cannot_unlet_imported_item_str), p);
8dc4782b60ff patch 8.2.4021: missing part of the :import changes
Bram Moolenaar <Bram@vim.org>
parents: 26935
diff changeset
157 ret = FAIL;
8dc4782b60ff patch 8.2.4021: missing part of the :import changes
Bram Moolenaar <Bram@vim.org>
parents: 26935
diff changeset
158 }
8dc4782b60ff patch 8.2.4021: missing part of the :import changes
Bram Moolenaar <Bram@vim.org>
parents: 26935
diff changeset
159 else
8dc4782b60ff patch 8.2.4021: missing part of the :import changes
Bram Moolenaar <Bram@vim.org>
parents: 26935
diff changeset
160 ret = compile_assign_unlet(p, &lhs, FALSE, &t_void, cctx);
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 vim_free(lhs.lhs_name);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 else if (check_vim9_unlet(p) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 ret = FAIL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 else
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 // Normal name. Only supports g:, w:, t: and b: namespaces.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 ret = generate_UNLET(cctx, ISN_UNLET, p, eap->forceit);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 *name_end = cc;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 return ret;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 * Callback passed to ex_unletlock().
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 static int
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 compile_lock_unlock(
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 lval_T *lvp,
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 char_u *name_end,
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 exarg_T *eap,
27394
69a48bcd1d80 patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 27299
diff changeset
187 int deep,
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 void *coookie)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 cctx_T *cctx = coookie;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 int cc = *name_end;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 char_u *p = lvp->ll_name;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 int ret = OK;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 size_t len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 char_u *buf;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 isntype_T isn = ISN_EXEC;
29742
2da1753e6a4a patch 9.0.0211: invalid memory access when compiling :lockvar
Bram Moolenaar <Bram@vim.org>
parents: 28598
diff changeset
197 char *cmd = eap->cmdidx == CMD_lockvar ? "lockvar" : "unlockvar";
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 if (cctx->ctx_skip == SKIP_YES)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 return OK;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201
29742
2da1753e6a4a patch 9.0.0211: invalid memory access when compiling :lockvar
Bram Moolenaar <Bram@vim.org>
parents: 28598
diff changeset
202 if (*p == NUL)
2da1753e6a4a patch 9.0.0211: invalid memory access when compiling :lockvar
Bram Moolenaar <Bram@vim.org>
parents: 28598
diff changeset
203 {
2da1753e6a4a patch 9.0.0211: invalid memory access when compiling :lockvar
Bram Moolenaar <Bram@vim.org>
parents: 28598
diff changeset
204 semsg(_(e_argument_required_for_str), cmd);
2da1753e6a4a patch 9.0.0211: invalid memory access when compiling :lockvar
Bram Moolenaar <Bram@vim.org>
parents: 28598
diff changeset
205 return FAIL;
2da1753e6a4a patch 9.0.0211: invalid memory access when compiling :lockvar
Bram Moolenaar <Bram@vim.org>
parents: 28598
diff changeset
206 }
2da1753e6a4a patch 9.0.0211: invalid memory access when compiling :lockvar
Bram Moolenaar <Bram@vim.org>
parents: 28598
diff changeset
207
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 // Cannot use :lockvar and :unlockvar on local variables.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 if (p[1] != ':')
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 char_u *end = find_name_end(p, NULL, NULL, FNE_CHECK_START);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 if (lookup_local(p, end - p, NULL, cctx) == OK)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 char_u *s = p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 if (*end != '.' && *end != '[')
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 emsg(_(e_cannot_lock_unlock_local_variable));
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 return FAIL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 // For "d.member" put the local variable on the stack, it will be
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 // passed to ex_lockvar() indirectly.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 if (compile_load(&s, end, cctx, FALSE, FALSE) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 return FAIL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 isn = ISN_LOCKUNLOCK;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 // Checking is done at runtime.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 *name_end = NUL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 len = name_end - p + 20;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 buf = alloc(len);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 if (buf == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 ret = FAIL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 else
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 {
27398
472bb63632bd patch 8.2.4227: Vim9: using "lockvar!" in :def function does not work
Bram Moolenaar <Bram@vim.org>
parents: 27394
diff changeset
239 if (deep < 0)
472bb63632bd patch 8.2.4227: Vim9: using "lockvar!" in :def function does not work
Bram Moolenaar <Bram@vim.org>
parents: 27394
diff changeset
240 vim_snprintf((char *)buf, len, "%s! %s", cmd, p);
472bb63632bd patch 8.2.4227: Vim9: using "lockvar!" in :def function does not work
Bram Moolenaar <Bram@vim.org>
parents: 27394
diff changeset
241 else
472bb63632bd patch 8.2.4227: Vim9: using "lockvar!" in :def function does not work
Bram Moolenaar <Bram@vim.org>
parents: 27394
diff changeset
242 vim_snprintf((char *)buf, len, "%s %d %s", cmd, deep, p);
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 ret = generate_EXEC_copy(cctx, isn, buf);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 vim_free(buf);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 *name_end = cc;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 return ret;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 * compile "unlet var", "lock var" and "unlock var"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 * "arg" points to "var".
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 compile_unletlock(char_u *arg, exarg_T *eap, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 {
27394
69a48bcd1d80 patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 27299
diff changeset
258 int deep = 0;
69a48bcd1d80 patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 27299
diff changeset
259 char_u *p = arg;
69a48bcd1d80 patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 27299
diff changeset
260
69a48bcd1d80 patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 27299
diff changeset
261 if (eap->cmdidx != CMD_unlet)
69a48bcd1d80 patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 27299
diff changeset
262 {
69a48bcd1d80 patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 27299
diff changeset
263 if (eap->forceit)
69a48bcd1d80 patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 27299
diff changeset
264 deep = -1;
69a48bcd1d80 patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 27299
diff changeset
265 else if (vim_isdigit(*p))
69a48bcd1d80 patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 27299
diff changeset
266 {
69a48bcd1d80 patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 27299
diff changeset
267 deep = getdigits(&p);
69a48bcd1d80 patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 27299
diff changeset
268 p = skipwhite(p);
69a48bcd1d80 patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 27299
diff changeset
269 }
69a48bcd1d80 patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 27299
diff changeset
270 else
69a48bcd1d80 patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 27299
diff changeset
271 deep = 2;
69a48bcd1d80 patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 27299
diff changeset
272 }
69a48bcd1d80 patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 27299
diff changeset
273
69a48bcd1d80 patch 8.2.4225: Vim9: depth argument of :lockvar not parsed in :def function
Bram Moolenaar <Bram@vim.org>
parents: 27299
diff changeset
274 ex_unletlock(eap, p, deep, GLV_NO_AUTOLOAD | GLV_COMPILING,
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 eap->cmdidx == CMD_unlet ? compile_unlet : compile_lock_unlock,
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 return eap->nextcmd == NULL ? (char_u *)"" : eap->nextcmd;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 * generate a jump to the ":endif"/":endfor"/":endwhile"/":finally"/":endtry".
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 static int
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 compile_jump_to_end(endlabel_T **el, jumpwhen_T when, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 garray_T *instr = &cctx->ctx_instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 endlabel_T *endlabel = ALLOC_CLEAR_ONE(endlabel_T);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 if (endlabel == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 return FAIL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 endlabel->el_next = *el;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 *el = endlabel;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 endlabel->el_end_label = instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 generate_JUMP(cctx, when, 0);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 return OK;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 static void
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 compile_fill_jump_to_end(endlabel_T **el, int jump_where, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 garray_T *instr = &cctx->ctx_instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 while (*el != NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 endlabel_T *cur = (*el);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 isn_T *isn;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 isn = ((isn_T *)instr->ga_data) + cur->el_end_label;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 isn->isn_arg.jump.jump_where = jump_where;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 *el = cur->el_next;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 vim_free(cur);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 static void
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 compile_free_jump_to_end(endlabel_T **el)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 while (*el != NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 endlabel_T *cur = (*el);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 *el = cur->el_next;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 vim_free(cur);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 * Create a new scope and set up the generic items.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 static scope_T *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 new_scope(cctx_T *cctx, scopetype_T type)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 scope_T *scope = ALLOC_CLEAR_ONE(scope_T);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 if (scope == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 scope->se_outer = cctx->ctx_scope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 cctx->ctx_scope = scope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 scope->se_type = type;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 scope->se_local_count = cctx->ctx_locals.ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 return scope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 * Free the current scope and go back to the outer scope.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 void
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 drop_scope(cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 scope_T *scope = cctx->ctx_scope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 if (scope == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 iemsg("calling drop_scope() without a scope");
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 return;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 cctx->ctx_scope = scope->se_outer;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 switch (scope->se_type)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 case IF_SCOPE:
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 compile_free_jump_to_end(&scope->se_u.se_if.is_end_label); break;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 case FOR_SCOPE:
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 compile_free_jump_to_end(&scope->se_u.se_for.fs_end_label); break;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 case WHILE_SCOPE:
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 compile_free_jump_to_end(&scope->se_u.se_while.ws_end_label); break;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 case TRY_SCOPE:
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 compile_free_jump_to_end(&scope->se_u.se_try.ts_end_label); break;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 case NO_SCOPE:
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 case BLOCK_SCOPE:
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 break;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 vim_free(scope);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 static int
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 misplaced_cmdmod(cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 garray_T *instr = &cctx->ctx_instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 if (cctx->ctx_has_cmdmod
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 && ((isn_T *)instr->ga_data)[instr->ga_len - 1].isn_type
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 == ISN_CMDMOD)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 emsg(_(e_misplaced_command_modifier));
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 return TRUE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 return FALSE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 * compile "if expr"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 * "if expr" Produces instructions:
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 * EVAL expr Push result of "expr"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 * JUMP_IF_FALSE end
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 * ... body ...
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 * end:
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 * "if expr | else" Produces instructions:
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 * EVAL expr Push result of "expr"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 * JUMP_IF_FALSE else
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 * ... body ...
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 * JUMP_ALWAYS end
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 * else:
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 * ... body ...
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 * end:
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 * "if expr1 | elseif expr2 | else" Produces instructions:
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 * EVAL expr Push result of "expr"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 * JUMP_IF_FALSE elseif
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 * ... body ...
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 * JUMP_ALWAYS end
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 * elseif:
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 * EVAL expr Push result of "expr"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 * JUMP_IF_FALSE else
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 * ... body ...
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 * JUMP_ALWAYS end
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 * else:
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 * ... body ...
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 * end:
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 compile_if(char_u *arg, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 char_u *p = arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 garray_T *instr = &cctx->ctx_instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 int instr_count = instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 scope_T *scope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 skip_T skip_save = cctx->ctx_skip;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 ppconst_T ppconst;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 CLEAR_FIELD(ppconst);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 if (compile_expr1(&p, cctx, &ppconst) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 clear_ppconst(&ppconst);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 if (!ends_excmd2(arg, skipwhite(p)))
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 {
26883
7f150a4936f2 patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
441 semsg(_(e_trailing_characters_str), p);
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 if (cctx->ctx_skip == SKIP_YES)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 clear_ppconst(&ppconst);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 else if (instr->ga_len == instr_count && ppconst.pp_used == 1)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 int error = FALSE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 int v;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 // The expression results in a constant.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 v = tv_get_bool_chk(&ppconst.pp_tv[0], &error);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 clear_ppconst(&ppconst);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 if (error)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 cctx->ctx_skip = v ? SKIP_NOT : SKIP_YES;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 else
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 // Not a constant, generate instructions for the expression.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 cctx->ctx_skip = SKIP_UNKNOWN;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 if (generate_ppconst(cctx, &ppconst) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 if (bool_on_stack(cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 // CMDMOD_REV must come before the jump
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 generate_undo_cmdmods(cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 scope = new_scope(cctx, IF_SCOPE);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 if (scope == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 scope->se_skip_save = skip_save;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 // "is_had_return" will be reset if any block does not end in :return
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 scope->se_u.se_if.is_had_return = TRUE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 if (cctx->ctx_skip == SKIP_UNKNOWN)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 // "where" is set when ":elseif", "else" or ":endif" is found
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 scope->se_u.se_if.is_if_label = instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 generate_JUMP(cctx, JUMP_IF_FALSE, 0);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 else
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 scope->se_u.se_if.is_if_label = -1;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 #ifdef FEAT_PROFILE
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 if (cctx->ctx_compile_type == CT_PROFILE && cctx->ctx_skip == SKIP_YES
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 && skip_save != SKIP_YES)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 // generated a profile start, need to generate a profile end, since it
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 // won't be done after returning
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 cctx->ctx_skip = SKIP_NOT;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 generate_instr(cctx, ISN_PROF_END);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 cctx->ctx_skip = SKIP_YES;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 #endif
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 return p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 compile_elseif(char_u *arg, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 char_u *p = arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 garray_T *instr = &cctx->ctx_instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 int instr_count;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 isn_T *isn;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 scope_T *scope = cctx->ctx_scope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 ppconst_T ppconst;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 skip_T save_skip = cctx->ctx_skip;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 if (scope == NULL || scope->se_type != IF_SCOPE)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 emsg(_(e_elseif_without_if));
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 unwind_locals(cctx, scope->se_local_count);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 if (!cctx->ctx_had_return)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 scope->se_u.se_if.is_had_return = FALSE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 if (cctx->ctx_skip == SKIP_NOT)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 // previous block was executed, this one and following will not
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 cctx->ctx_skip = SKIP_YES;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 scope->se_u.se_if.is_seen_skip_not = TRUE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 if (scope->se_u.se_if.is_seen_skip_not)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 // A previous block was executed, skip over expression and bail out.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 // Do not count the "elseif" for profiling and cmdmod
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 instr->ga_len = current_instr_idx(cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 skip_expr_cctx(&p, cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 return p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 if (cctx->ctx_skip == SKIP_UNKNOWN)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 int moved_cmdmod = FALSE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 int saved_debug = FALSE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 isn_T debug_isn;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 // Move any CMDMOD instruction to after the jump
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 if (((isn_T *)instr->ga_data)[instr->ga_len - 1].isn_type == ISN_CMDMOD)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 if (GA_GROW_FAILS(instr, 1))
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 ((isn_T *)instr->ga_data)[instr->ga_len] =
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 ((isn_T *)instr->ga_data)[instr->ga_len - 1];
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 --instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 moved_cmdmod = TRUE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 // Remove the already generated ISN_DEBUG, it is written below the
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 // ISN_FOR instruction.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 if (cctx->ctx_compile_type == CT_DEBUG && instr->ga_len > 0
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 && ((isn_T *)instr->ga_data)[instr->ga_len - 1]
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 .isn_type == ISN_DEBUG)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 --instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 debug_isn = ((isn_T *)instr->ga_data)[instr->ga_len];
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 saved_debug = TRUE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 if (compile_jump_to_end(&scope->se_u.se_if.is_end_label,
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 JUMP_ALWAYS, cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 // previous "if" or "elseif" jumps here
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_if.is_if_label;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 isn->isn_arg.jump.jump_where = instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 if (moved_cmdmod)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 ++instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 if (saved_debug)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 // move the debug instruction here
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 if (GA_GROW_FAILS(instr, 1))
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 ((isn_T *)instr->ga_data)[instr->ga_len] = debug_isn;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 ++instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 // compile "expr"; if we know it evaluates to FALSE skip the block
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 CLEAR_FIELD(ppconst);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 if (cctx->ctx_skip == SKIP_YES)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 cctx->ctx_skip = SKIP_UNKNOWN;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 #ifdef FEAT_PROFILE
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 if (cctx->ctx_compile_type == CT_PROFILE)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 // the previous block was skipped, need to profile this line
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 generate_instr(cctx, ISN_PROF_START);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 #endif
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 if (cctx->ctx_compile_type == CT_DEBUG)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 // the previous block was skipped, may want to debug this line
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 generate_instr_debug(cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 instr_count = instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 if (compile_expr1(&p, cctx, &ppconst) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 clear_ppconst(&ppconst);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 cctx->ctx_skip = save_skip;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 if (!ends_excmd2(arg, skipwhite(p)))
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 clear_ppconst(&ppconst);
26883
7f150a4936f2 patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
611 semsg(_(e_trailing_characters_str), p);
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 if (scope->se_skip_save == SKIP_YES)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 clear_ppconst(&ppconst);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 else if (instr->ga_len == instr_count && ppconst.pp_used == 1)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 int error = FALSE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 int v;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 // The expression result is a constant.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 v = tv_get_bool_chk(&ppconst.pp_tv[0], &error);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 if (error)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 clear_ppconst(&ppconst);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 cctx->ctx_skip = v ? SKIP_NOT : SKIP_YES;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 clear_ppconst(&ppconst);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 scope->se_u.se_if.is_if_label = -1;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 else
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 // Not a constant, generate instructions for the expression.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 cctx->ctx_skip = SKIP_UNKNOWN;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 if (generate_ppconst(cctx, &ppconst) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 if (bool_on_stack(cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 // CMDMOD_REV must come before the jump
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 generate_undo_cmdmods(cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 // "where" is set when ":elseif", "else" or ":endif" is found
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 scope->se_u.se_if.is_if_label = instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 generate_JUMP(cctx, JUMP_IF_FALSE, 0);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 return p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 compile_else(char_u *arg, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 char_u *p = arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 garray_T *instr = &cctx->ctx_instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 isn_T *isn;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 scope_T *scope = cctx->ctx_scope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 if (scope == NULL || scope->se_type != IF_SCOPE)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 emsg(_(e_else_without_if));
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 unwind_locals(cctx, scope->se_local_count);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 if (!cctx->ctx_had_return)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 scope->se_u.se_if.is_had_return = FALSE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 scope->se_u.se_if.is_seen_else = TRUE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 #ifdef FEAT_PROFILE
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 if (cctx->ctx_compile_type == CT_PROFILE)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 if (cctx->ctx_skip == SKIP_NOT
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 && ((isn_T *)instr->ga_data)[instr->ga_len - 1]
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 .isn_type == ISN_PROF_START)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 // the previous block was executed, do not count "else" for
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 // profiling
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 --instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 if (cctx->ctx_skip == SKIP_YES && !scope->se_u.se_if.is_seen_skip_not)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 // the previous block was not executed, this one will, do count the
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 // "else" for profiling
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 cctx->ctx_skip = SKIP_NOT;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 generate_instr(cctx, ISN_PROF_END);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 generate_instr(cctx, ISN_PROF_START);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 cctx->ctx_skip = SKIP_YES;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 #endif
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 if (!scope->se_u.se_if.is_seen_skip_not && scope->se_skip_save != SKIP_YES)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 // jump from previous block to the end, unless the else block is empty
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 if (cctx->ctx_skip == SKIP_UNKNOWN)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 if (!cctx->ctx_had_return
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 && compile_jump_to_end(&scope->se_u.se_if.is_end_label,
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 JUMP_ALWAYS, cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 if (cctx->ctx_skip == SKIP_UNKNOWN)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 if (scope->se_u.se_if.is_if_label >= 0)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 // previous "if" or "elseif" jumps here
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_if.is_if_label;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 isn->isn_arg.jump.jump_where = instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 scope->se_u.se_if.is_if_label = -1;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 if (cctx->ctx_skip != SKIP_UNKNOWN)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 cctx->ctx_skip = cctx->ctx_skip == SKIP_YES ? SKIP_NOT : SKIP_YES;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 return p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 compile_endif(char_u *arg, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 scope_T *scope = cctx->ctx_scope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 ifscope_T *ifscope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 garray_T *instr = &cctx->ctx_instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 isn_T *isn;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 if (misplaced_cmdmod(cctx))
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 if (scope == NULL || scope->se_type != IF_SCOPE)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 emsg(_(e_endif_without_if));
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 ifscope = &scope->se_u.se_if;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 unwind_locals(cctx, scope->se_local_count);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 if (!cctx->ctx_had_return)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 ifscope->is_had_return = FALSE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 if (scope->se_u.se_if.is_if_label >= 0)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 // previous "if" or "elseif" jumps here
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_if.is_if_label;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 isn->isn_arg.jump.jump_where = instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 // Fill in the "end" label in jumps at the end of the blocks.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 compile_fill_jump_to_end(&ifscope->is_end_label, instr->ga_len, cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 #ifdef FEAT_PROFILE
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 // even when skipping we count the endif as executed, unless the block it's
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 // in is skipped
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 if (cctx->ctx_compile_type == CT_PROFILE && cctx->ctx_skip == SKIP_YES
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 && scope->se_skip_save != SKIP_YES)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 cctx->ctx_skip = SKIP_NOT;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 generate_instr(cctx, ISN_PROF_START);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 #endif
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 cctx->ctx_skip = scope->se_skip_save;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 // If all the blocks end in :return and there is an :else then the
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 // had_return flag is set.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 cctx->ctx_had_return = ifscope->is_had_return && ifscope->is_seen_else;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 drop_scope(cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 return arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 * Compile "for var in expr":
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 * Produces instructions:
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 * PUSHNR -1
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 * STORE loop-idx Set index to -1
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 * EVAL expr result of "expr" on top of stack
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 * top: FOR loop-idx, end Increment index, use list on bottom of stack
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 * - if beyond end, jump to "end"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 * - otherwise get item from list and push it
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 * STORE var Store item in "var"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 * ... body ...
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 * JUMP top Jump back to repeat
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 * end: DROP Drop the result of "expr"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 * Compile "for [var1, var2] in expr" - as above, but instead of "STORE var":
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 * UNPACK 2 Split item in 2
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 * STORE var1 Store item in "var1"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 * STORE var2 Store item in "var2"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 compile_for(char_u *arg_start, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 char_u *arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 char_u *arg_end;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 char_u *name = NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 char_u *p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 char_u *wp;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 int var_count = 0;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 int var_list = FALSE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 int semicolon = FALSE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 size_t varlen;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 garray_T *instr = &cctx->ctx_instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 scope_T *scope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 lvar_T *loop_lvar; // loop iteration variable
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 lvar_T *var_lvar; // variable for "var"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 type_T *vartype;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 type_T *item_type = &t_any;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 int idx;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 int prev_lnum = cctx->ctx_prev_lnum;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 p = skip_var_list(arg_start, TRUE, &var_count, &semicolon, FALSE);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 if (p == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 if (var_count == 0)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 var_count = 1;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 else
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 var_list = TRUE; // can also be a list of one variable
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 // consume "in"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 wp = p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 if (may_get_next_line_error(wp, &p, cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 if (STRNCMP(p, "in", 2) != 0 || !IS_WHITE_OR_NUL(p[2]))
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 if (*p == ':' && wp != p)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 semsg(_(e_no_white_space_allowed_before_colon_str), p);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 else
26887
612339679616 patch 8.2.3972: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26883
diff changeset
828 emsg(_(e_missing_in_after_for));
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 wp = p + 2;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 if (may_get_next_line_error(wp, &p, cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834
26905
c2186e32ae42 patch 8.2.3981: Vim9: debugging a for loop doesn't stop before it starts
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
835 // Find the already generated ISN_DEBUG to get the line number for the
c2186e32ae42 patch 8.2.3981: Vim9: debugging a for loop doesn't stop before it starts
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
836 // instruction written below the ISN_FOR instruction.
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 if (cctx->ctx_compile_type == CT_DEBUG && instr->ga_len > 0
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 && ((isn_T *)instr->ga_data)[instr->ga_len - 1]
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 .isn_type == ISN_DEBUG)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 {
26905
c2186e32ae42 patch 8.2.3981: Vim9: debugging a for loop doesn't stop before it starts
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
841 prev_lnum = ((isn_T *)instr->ga_data)[instr->ga_len - 1]
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 .isn_arg.debug.dbg_break_lnum;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 scope = new_scope(cctx, FOR_SCOPE);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 if (scope == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 // Reserve a variable to store the loop iteration counter and initialize it
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 // to -1.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 loop_lvar = reserve_local(cctx, (char_u *)"", 0, FALSE, &t_number);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 if (loop_lvar == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 // out of memory
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 drop_scope(cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 generate_STORENR(cctx, loop_lvar->lv_idx, -1);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 // compile "expr", it remains on the stack until "endfor"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 arg = p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 if (compile_expr0(&arg, cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 drop_scope(cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 arg_end = arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 if (cctx->ctx_skip != SKIP_YES)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 {
26771
fc859aea8cec patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents: 26729
diff changeset
871 // If we know the type of "var" and it is not a supported type we can
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 // give an error now.
26935
ccb9be1cdd71 patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents: 26905
diff changeset
873 vartype = get_type_on_stack(cctx, 0);
26674
38a270fdd3f6 patch 8.2.3866: Vim9: type checking global variables is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26672
diff changeset
874 if (vartype->tt_type != VAR_LIST
38a270fdd3f6 patch 8.2.3866: Vim9: type checking global variables is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26672
diff changeset
875 && vartype->tt_type != VAR_STRING
38a270fdd3f6 patch 8.2.3866: Vim9: type checking global variables is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26672
diff changeset
876 && vartype->tt_type != VAR_BLOB
38a270fdd3f6 patch 8.2.3866: Vim9: type checking global variables is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26672
diff changeset
877 && vartype->tt_type != VAR_ANY
38a270fdd3f6 patch 8.2.3866: Vim9: type checking global variables is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26672
diff changeset
878 && vartype->tt_type != VAR_UNKNOWN)
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 semsg(_(e_for_loop_on_str_not_supported),
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 vartype_name(vartype->tt_type));
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 drop_scope(cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 if (vartype->tt_type == VAR_STRING)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 item_type = &t_string;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 else if (vartype->tt_type == VAR_BLOB)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 item_type = &t_number;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 else if (vartype->tt_type == VAR_LIST
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 && vartype->tt_member->tt_type != VAR_ANY)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 if (!var_list)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 item_type = vartype->tt_member;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 else if (vartype->tt_member->tt_type == VAR_LIST
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 && vartype->tt_member->tt_member->tt_type != VAR_ANY)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 item_type = vartype->tt_member->tt_member;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 // CMDMOD_REV must come before the FOR instruction.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 generate_undo_cmdmods(cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 // "for_end" is set when ":endfor" is found
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 scope->se_u.se_for.fs_top_label = current_instr_idx(cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905
26905
c2186e32ae42 patch 8.2.3981: Vim9: debugging a for loop doesn't stop before it starts
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
906 if (cctx->ctx_compile_type == CT_DEBUG)
c2186e32ae42 patch 8.2.3981: Vim9: debugging a for loop doesn't stop before it starts
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
907 {
c2186e32ae42 patch 8.2.3981: Vim9: debugging a for loop doesn't stop before it starts
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
908 int save_prev_lnum = cctx->ctx_prev_lnum;
c2186e32ae42 patch 8.2.3981: Vim9: debugging a for loop doesn't stop before it starts
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
909 isn_T *isn;
c2186e32ae42 patch 8.2.3981: Vim9: debugging a for loop doesn't stop before it starts
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
910
c2186e32ae42 patch 8.2.3981: Vim9: debugging a for loop doesn't stop before it starts
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
911 // Add ISN_DEBUG here, before deciding to end the loop. There will
c2186e32ae42 patch 8.2.3981: Vim9: debugging a for loop doesn't stop before it starts
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
912 // be another ISN_DEBUG before the next instruction.
c2186e32ae42 patch 8.2.3981: Vim9: debugging a for loop doesn't stop before it starts
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
913 // Use the prev_lnum from the ISN_DEBUG instruction removed above.
c2186e32ae42 patch 8.2.3981: Vim9: debugging a for loop doesn't stop before it starts
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
914 // Increment the variable count so that the loop variable can be
c2186e32ae42 patch 8.2.3981: Vim9: debugging a for loop doesn't stop before it starts
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
915 // inspected.
c2186e32ae42 patch 8.2.3981: Vim9: debugging a for loop doesn't stop before it starts
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
916 cctx->ctx_prev_lnum = prev_lnum;
c2186e32ae42 patch 8.2.3981: Vim9: debugging a for loop doesn't stop before it starts
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
917 isn = generate_instr_debug(cctx);
c2186e32ae42 patch 8.2.3981: Vim9: debugging a for loop doesn't stop before it starts
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
918 ++isn->isn_arg.debug.dbg_var_names_len;
c2186e32ae42 patch 8.2.3981: Vim9: debugging a for loop doesn't stop before it starts
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
919 cctx->ctx_prev_lnum = save_prev_lnum;
c2186e32ae42 patch 8.2.3981: Vim9: debugging a for loop doesn't stop before it starts
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
920 }
c2186e32ae42 patch 8.2.3981: Vim9: debugging a for loop doesn't stop before it starts
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
921
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 generate_FOR(cctx, loop_lvar->lv_idx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 arg = arg_start;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 if (var_list)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 generate_UNPACK(cctx, var_count, semicolon);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 arg = skipwhite(arg + 1); // skip white after '['
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929
26935
ccb9be1cdd71 patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents: 26905
diff changeset
930 // drop the list item
ccb9be1cdd71 patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents: 26905
diff changeset
931 --cctx->ctx_type_stack.ga_len;
ccb9be1cdd71 patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents: 26905
diff changeset
932
ccb9be1cdd71 patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents: 26905
diff changeset
933 // add type of the items
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 for (idx = 0; idx < var_count; ++idx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 {
26935
ccb9be1cdd71 patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents: 26905
diff changeset
936 type_T *type = (semicolon && idx == 0) ? vartype : item_type;
ccb9be1cdd71 patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents: 26905
diff changeset
937
ccb9be1cdd71 patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents: 26905
diff changeset
938 if (push_type_stack(cctx, type) == FAIL)
ccb9be1cdd71 patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents: 26905
diff changeset
939 {
ccb9be1cdd71 patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents: 26905
diff changeset
940 drop_scope(cctx);
ccb9be1cdd71 patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents: 26905
diff changeset
941 return NULL;
ccb9be1cdd71 patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents: 26905
diff changeset
942 }
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 for (idx = 0; idx < var_count; ++idx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 assign_dest_T dest = dest_local;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 int opt_flags = 0;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 int vimvaridx = -1;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 type_T *type = &t_any;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 type_T *lhs_type = &t_any;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 where_T where = WHERE_INIT;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 p = skip_var_one(arg, FALSE);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 varlen = p - arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 name = vim_strnsave(arg, varlen);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 if (name == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 goto failed;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 if (*p == ':')
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 p = skipwhite(p + 1);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 lhs_type = parse_type(&p, cctx->ctx_type_list, TRUE);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 if (get_var_dest(name, &dest, CMD_for, &opt_flags,
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 &vimvaridx, &type, cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 goto failed;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 if (dest != dest_local)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 if (generate_store_var(cctx, dest, opt_flags, vimvaridx,
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 0, 0, type, name) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 goto failed;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 else if (varlen == 1 && *arg == '_')
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 // Assigning to "_": drop the value.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 if (generate_instr_drop(cctx, ISN_DROP, 1) == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 goto failed;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 else
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 // Script var is not supported.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 if (STRNCMP(name, "s:", 2) == 0)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 emsg(_(e_cannot_use_script_variable_in_for_loop));
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 goto failed;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 if (!valid_varname(arg, (int)varlen, FALSE))
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 goto failed;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 if (lookup_local(arg, varlen, NULL, cctx) == OK)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 semsg(_(e_variable_already_declared), arg);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 goto failed;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 // Reserve a variable to store "var".
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 where.wt_index = var_list ? idx + 1 : 0;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 where.wt_variable = TRUE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 if (lhs_type == &t_any)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 lhs_type = item_type;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 else if (item_type != &t_unknown
27515
1aff400b819e patch 8.2.4285: Vim9: type of item in for loop not checked properly
Bram Moolenaar <Bram@vim.org>
parents: 27398
diff changeset
1004 && need_type_where(item_type, lhs_type, -1,
1aff400b819e patch 8.2.4285: Vim9: type of item in for loop not checked properly
Bram Moolenaar <Bram@vim.org>
parents: 27398
diff changeset
1005 where, cctx, FALSE, FALSE) == FAIL)
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 goto failed;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 var_lvar = reserve_local(cctx, arg, varlen, TRUE, lhs_type);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 if (var_lvar == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 // out of memory or used as an argument
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 goto failed;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 if (semicolon && idx == var_count - 1)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 var_lvar->lv_type = vartype;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 generate_STORE(cctx, ISN_STORE, var_lvar->lv_idx, NULL);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 if (*p == ',' || *p == ';')
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 ++p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 arg = skipwhite(p);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 vim_free(name);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 return arg_end;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 failed:
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 vim_free(name);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 drop_scope(cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 * compile "endfor"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 compile_endfor(char_u *arg, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 garray_T *instr = &cctx->ctx_instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 scope_T *scope = cctx->ctx_scope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 forscope_T *forscope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 isn_T *isn;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 if (misplaced_cmdmod(cctx))
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 if (scope == NULL || scope->se_type != FOR_SCOPE)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26857
diff changeset
1048 emsg(_(e_endfor_without_for));
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 forscope = &scope->se_u.se_for;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 cctx->ctx_scope = scope->se_outer;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 if (cctx->ctx_skip != SKIP_YES)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 unwind_locals(cctx, scope->se_local_count);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 // At end of ":for" scope jump back to the FOR instruction.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 generate_JUMP(cctx, JUMP_ALWAYS, forscope->fs_top_label);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 // Fill in the "end" label in the FOR statement so it can jump here.
26905
c2186e32ae42 patch 8.2.3981: Vim9: debugging a for loop doesn't stop before it starts
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
1061 // In debug mode an ISN_DEBUG was inserted.
c2186e32ae42 patch 8.2.3981: Vim9: debugging a for loop doesn't stop before it starts
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
1062 isn = ((isn_T *)instr->ga_data) + forscope->fs_top_label
c2186e32ae42 patch 8.2.3981: Vim9: debugging a for loop doesn't stop before it starts
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
1063 + (cctx->ctx_compile_type == CT_DEBUG ? 1 : 0);
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 isn->isn_arg.forloop.for_end = instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 // Fill in the "end" label any BREAK statements
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 compile_fill_jump_to_end(&forscope->fs_end_label, instr->ga_len, cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 // Below the ":for" scope drop the "expr" list from the stack.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 if (generate_instr_drop(cctx, ISN_DROP, 1) == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 vim_free(scope);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 return arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 * compile "while expr"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 * Produces instructions:
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 * top: EVAL expr Push result of "expr"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 * JUMP_IF_FALSE end jump if false
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 * ... body ...
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 * JUMP top Jump back to repeat
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 * end:
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088 *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 compile_while(char_u *arg, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 char_u *p = arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 scope_T *scope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 scope = new_scope(cctx, WHILE_SCOPE);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 if (scope == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 // "endwhile" jumps back here, one before when profiling or using cmdmods
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 scope->se_u.se_while.ws_top_label = current_instr_idx(cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 // compile "expr"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 if (compile_expr0(&p, cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 if (!ends_excmd2(arg, skipwhite(p)))
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 {
26883
7f150a4936f2 patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
1109 semsg(_(e_trailing_characters_str), p);
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 if (cctx->ctx_skip != SKIP_YES)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 if (bool_on_stack(cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 return FAIL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 // CMDMOD_REV must come before the jump
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 generate_undo_cmdmods(cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 // "while_end" is set when ":endwhile" is found
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 if (compile_jump_to_end(&scope->se_u.se_while.ws_end_label,
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 JUMP_IF_FALSE, cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 return FAIL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 return p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131 * compile "endwhile"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 compile_endwhile(char_u *arg, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 scope_T *scope = cctx->ctx_scope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 garray_T *instr = &cctx->ctx_instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 if (misplaced_cmdmod(cctx))
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 if (scope == NULL || scope->se_type != WHILE_SCOPE)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26857
diff changeset
1143 emsg(_(e_endwhile_without_while));
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 cctx->ctx_scope = scope->se_outer;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 if (cctx->ctx_skip != SKIP_YES)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 unwind_locals(cctx, scope->se_local_count);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 #ifdef FEAT_PROFILE
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 // count the endwhile before jumping
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 may_generate_prof_end(cctx, cctx->ctx_lnum);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 #endif
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 // At end of ":for" scope jump back to the FOR instruction.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 generate_JUMP(cctx, JUMP_ALWAYS, scope->se_u.se_while.ws_top_label);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 // Fill in the "end" label in the WHILE statement so it can jump here.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 // And in any jumps for ":break"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 compile_fill_jump_to_end(&scope->se_u.se_while.ws_end_label,
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 instr->ga_len, cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 vim_free(scope);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 return arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 * compile "continue"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 compile_continue(char_u *arg, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 scope_T *scope = cctx->ctx_scope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 int try_scopes = 0;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 int loop_label;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180 for (;;)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 if (scope == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 {
26887
612339679616 patch 8.2.3972: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26883
diff changeset
1184 emsg(_(e_continue_without_while_or_for));
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 if (scope->se_type == FOR_SCOPE)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 loop_label = scope->se_u.se_for.fs_top_label;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 break;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 if (scope->se_type == WHILE_SCOPE)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 loop_label = scope->se_u.se_while.ws_top_label;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 break;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 if (scope->se_type == TRY_SCOPE)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 ++try_scopes;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199 scope = scope->se_outer;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 if (try_scopes > 0)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 // Inside one or more try/catch blocks we first need to jump to the
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 // "finally" or "endtry" to cleanup.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205 generate_TRYCONT(cctx, try_scopes, loop_label);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 else
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 // Jump back to the FOR or WHILE instruction.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208 generate_JUMP(cctx, JUMP_ALWAYS, loop_label);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1209
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210 return arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1214 * compile "break"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 compile_break(char_u *arg, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 scope_T *scope = cctx->ctx_scope;
28035
9f8535cf6f1b patch 8.2.4542: Vim9: "break" inside try/catch not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 27891
diff changeset
1220 int try_scopes = 0;
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 endlabel_T **el;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223 for (;;)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 if (scope == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 {
26887
612339679616 patch 8.2.3972: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26883
diff changeset
1227 emsg(_(e_break_without_while_or_for));
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 }
28035
9f8535cf6f1b patch 8.2.4542: Vim9: "break" inside try/catch not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 27891
diff changeset
1230 if (scope->se_type == FOR_SCOPE)
9f8535cf6f1b patch 8.2.4542: Vim9: "break" inside try/catch not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 27891
diff changeset
1231 {
9f8535cf6f1b patch 8.2.4542: Vim9: "break" inside try/catch not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 27891
diff changeset
1232 el = &scope->se_u.se_for.fs_end_label;
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233 break;
28035
9f8535cf6f1b patch 8.2.4542: Vim9: "break" inside try/catch not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 27891
diff changeset
1234 }
9f8535cf6f1b patch 8.2.4542: Vim9: "break" inside try/catch not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 27891
diff changeset
1235 if (scope->se_type == WHILE_SCOPE)
9f8535cf6f1b patch 8.2.4542: Vim9: "break" inside try/catch not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 27891
diff changeset
1236 {
9f8535cf6f1b patch 8.2.4542: Vim9: "break" inside try/catch not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 27891
diff changeset
1237 el = &scope->se_u.se_while.ws_end_label;
9f8535cf6f1b patch 8.2.4542: Vim9: "break" inside try/catch not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 27891
diff changeset
1238 break;
9f8535cf6f1b patch 8.2.4542: Vim9: "break" inside try/catch not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 27891
diff changeset
1239 }
9f8535cf6f1b patch 8.2.4542: Vim9: "break" inside try/catch not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 27891
diff changeset
1240 if (scope->se_type == TRY_SCOPE)
9f8535cf6f1b patch 8.2.4542: Vim9: "break" inside try/catch not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 27891
diff changeset
1241 ++try_scopes;
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1242 scope = scope->se_outer;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1243 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244
28035
9f8535cf6f1b patch 8.2.4542: Vim9: "break" inside try/catch not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 27891
diff changeset
1245 if (try_scopes > 0)
9f8535cf6f1b patch 8.2.4542: Vim9: "break" inside try/catch not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 27891
diff changeset
1246 // Inside one or more try/catch blocks we first need to jump to the
9f8535cf6f1b patch 8.2.4542: Vim9: "break" inside try/catch not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 27891
diff changeset
1247 // "finally" or "endtry" to cleanup. Then come to the next JUMP
9f8535cf6f1b patch 8.2.4542: Vim9: "break" inside try/catch not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 27891
diff changeset
1248 // intruction, which we don't know the index of yet.
9f8535cf6f1b patch 8.2.4542: Vim9: "break" inside try/catch not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 27891
diff changeset
1249 generate_TRYCONT(cctx, try_scopes, cctx->ctx_instr.ga_len + 1);
9f8535cf6f1b patch 8.2.4542: Vim9: "break" inside try/catch not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 27891
diff changeset
1250
9f8535cf6f1b patch 8.2.4542: Vim9: "break" inside try/catch not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 27891
diff changeset
1251 // Jump to the end of the FOR or WHILE loop. The instruction index will be
9f8535cf6f1b patch 8.2.4542: Vim9: "break" inside try/catch not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 27891
diff changeset
1252 // filled in later.
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253 if (compile_jump_to_end(el, JUMP_ALWAYS, cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 return FAIL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 return arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260 * compile "{" start of block
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1263 compile_block(char_u *arg, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 if (new_scope(cctx, BLOCK_SCOPE) == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1266 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 return skipwhite(arg + 1);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 * compile end of block: drop one scope
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273 void
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 compile_endblock(cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1276 scope_T *scope = cctx->ctx_scope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 cctx->ctx_scope = scope->se_outer;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 unwind_locals(cctx, scope->se_local_count);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 vim_free(scope);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284 * Compile "try".
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 * Creates a new scope for the try-endtry, pointing to the first catch and
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286 * finally.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287 * Creates another scope for the "try" block itself.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288 * TRY instruction sets up exception handling at runtime.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289 *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290 * "try"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 * TRY -> catch1, -> finally push trystack entry
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 * ... try block
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 * "throw {exception}"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 * EVAL {exception}
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 * THROW create exception
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1296 * ... try block
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297 * " catch {expr}"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 * JUMP -> finally
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1299 * catch1: PUSH exception
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 * EVAL {expr}
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 * MATCH
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302 * JUMP nomatch -> catch2
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1303 * CATCH remove exception
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1304 * ... catch block
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1305 * " catch"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306 * JUMP -> finally
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1307 * catch2: CATCH remove exception
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1308 * ... catch block
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309 * " finally"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1310 * finally:
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1311 * ... finally block
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1312 * " endtry"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1313 * ENDTRY pop trystack entry, may rethrow
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1315 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 compile_try(char_u *arg, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1317 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1318 garray_T *instr = &cctx->ctx_instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1319 scope_T *try_scope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1320 scope_T *scope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1321
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1322 if (misplaced_cmdmod(cctx))
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1323 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1324
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325 // scope that holds the jumps that go to catch/finally/endtry
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 try_scope = new_scope(cctx, TRY_SCOPE);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 if (try_scope == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1329
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 if (cctx->ctx_skip != SKIP_YES)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 isn_T *isn;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 // "try_catch" is set when the first ":catch" is found or when no catch
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 // is found and ":finally" is found.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 // "try_finally" is set when ":finally" is found
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1337 // "try_endtry" is set when ":endtry" is found
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1338 try_scope->se_u.se_try.ts_try_label = instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1339 if ((isn = generate_instr(cctx, ISN_TRY)) == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1340 return NULL;
26672
3516017e5f54 patch 8.2.3865: Vim9: compiler complains about using "try" as a struct member
Bram Moolenaar <Bram@vim.org>
parents: 26662
diff changeset
1341 isn->isn_arg.tryref.try_ref = ALLOC_CLEAR_ONE(tryref_T);
3516017e5f54 patch 8.2.3865: Vim9: compiler complains about using "try" as a struct member
Bram Moolenaar <Bram@vim.org>
parents: 26662
diff changeset
1342 if (isn->isn_arg.tryref.try_ref == NULL)
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1343 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1344 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1346 // scope for the try block itself
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1347 scope = new_scope(cctx, BLOCK_SCOPE);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348 if (scope == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1349 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1350
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1351 return arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1353
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 * Compile "catch {expr}".
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1356 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 compile_catch(char_u *arg, cctx_T *cctx UNUSED)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1359 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1360 scope_T *scope = cctx->ctx_scope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 garray_T *instr = &cctx->ctx_instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1362 char_u *p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363 isn_T *isn;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1364
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365 if (misplaced_cmdmod(cctx))
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1368 // end block scope from :try or :catch
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 if (scope != NULL && scope->se_type == BLOCK_SCOPE)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1370 compile_endblock(cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 scope = cctx->ctx_scope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373 // Error if not in a :try scope
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1374 if (scope == NULL || scope->se_type != TRY_SCOPE)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1375 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26857
diff changeset
1376 emsg(_(e_catch_without_try));
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1377 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1380 if (scope->se_u.se_try.ts_caught_all)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1382 emsg(_(e_catch_unreachable_after_catch_all));
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384 }
27084
6fc63c6a7ee7 patch 8.2.4071: Vim9: no detection of return in try/endtry
Bram Moolenaar <Bram@vim.org>
parents: 26984
diff changeset
1385 if (!cctx->ctx_had_return)
6fc63c6a7ee7 patch 8.2.4071: Vim9: no detection of return in try/endtry
Bram Moolenaar <Bram@vim.org>
parents: 26984
diff changeset
1386 scope->se_u.se_try.ts_no_return = TRUE;
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1387
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 if (cctx->ctx_skip != SKIP_YES)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390 #ifdef FEAT_PROFILE
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1391 // the profile-start should be after the jump
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1392 if (cctx->ctx_compile_type == CT_PROFILE
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393 && instr->ga_len > 0
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1394 && ((isn_T *)instr->ga_data)[instr->ga_len - 1]
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 .isn_type == ISN_PROF_START)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1396 --instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1397 #endif
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1398 // Jump from end of previous block to :finally or :endtry
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1399 if (compile_jump_to_end(&scope->se_u.se_try.ts_end_label,
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1400 JUMP_ALWAYS, cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1401 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 // End :try or :catch scope: set value in ISN_TRY instruction
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_try_label;
26672
3516017e5f54 patch 8.2.3865: Vim9: compiler complains about using "try" as a struct member
Bram Moolenaar <Bram@vim.org>
parents: 26662
diff changeset
1405 if (isn->isn_arg.tryref.try_ref->try_catch == 0)
3516017e5f54 patch 8.2.3865: Vim9: compiler complains about using "try" as a struct member
Bram Moolenaar <Bram@vim.org>
parents: 26662
diff changeset
1406 isn->isn_arg.tryref.try_ref->try_catch = instr->ga_len;
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1407 if (scope->se_u.se_try.ts_catch_label != 0)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1408 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1409 // Previous catch without match jumps here
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1410 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_catch_label;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1411 isn->isn_arg.jump.jump_where = instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1412 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413 #ifdef FEAT_PROFILE
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1414 if (cctx->ctx_compile_type == CT_PROFILE)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1415 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1416 // a "throw" that jumps here needs to be counted
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 generate_instr(cctx, ISN_PROF_END);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 // the "catch" is also counted
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1419 generate_instr(cctx, ISN_PROF_START);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1421 #endif
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1422 if (cctx->ctx_compile_type == CT_DEBUG)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1423 generate_instr_debug(cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1424 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1426 p = skipwhite(arg);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1427 if (ends_excmd2(arg, p))
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1428 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1429 scope->se_u.se_try.ts_caught_all = TRUE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1430 scope->se_u.se_try.ts_catch_label = 0;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1431 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1432 else
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1433 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1434 char_u *end;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1435 char_u *pat;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1436 char_u *tofree = NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1437 int dropped = 0;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1438 int len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1439
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440 // Push v:exception, push {expr} and MATCH
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1441 generate_instr_type(cctx, ISN_PUSHEXC, &t_string);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1442
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1443 end = skip_regexp_ex(p + 1, *p, TRUE, &tofree, &dropped, NULL);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1444 if (*end != *p)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1445 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1446 semsg(_(e_separator_mismatch_str), p);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1447 vim_free(tofree);
27583
d4921b91542c patch 8.2.4318: various comment and indent mistakes, returning wrong zero
Bram Moolenaar <Bram@vim.org>
parents: 27515
diff changeset
1448 return NULL;
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1449 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1450 if (tofree == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1451 len = (int)(end - (p + 1));
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1452 else
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1453 len = (int)(end - tofree);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454 pat = vim_strnsave(tofree == NULL ? p + 1 : tofree, len);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455 vim_free(tofree);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1456 p += len + 2 + dropped;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1457 if (pat == NULL)
27583
d4921b91542c patch 8.2.4318: various comment and indent mistakes, returning wrong zero
Bram Moolenaar <Bram@vim.org>
parents: 27515
diff changeset
1458 return NULL;
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1459 if (generate_PUSHS(cctx, &pat) == FAIL)
27583
d4921b91542c patch 8.2.4318: various comment and indent mistakes, returning wrong zero
Bram Moolenaar <Bram@vim.org>
parents: 27515
diff changeset
1460 return NULL;
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1461
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1462 if (generate_COMPARE(cctx, EXPR_MATCH, FALSE) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1463 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1464
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1465 scope->se_u.se_try.ts_catch_label = instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1466 if (generate_JUMP(cctx, JUMP_IF_FALSE, 0) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1467 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1468 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1469
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1470 if (cctx->ctx_skip != SKIP_YES && generate_instr(cctx, ISN_CATCH) == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1471 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1472
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473 if (new_scope(cctx, BLOCK_SCOPE) == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1475 return p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1476 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1478 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479 compile_finally(char_u *arg, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1480 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481 scope_T *scope = cctx->ctx_scope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1482 garray_T *instr = &cctx->ctx_instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1483 isn_T *isn;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1484 int this_instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1485
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1486 if (misplaced_cmdmod(cctx))
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1487 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1488
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1489 // end block scope from :try or :catch
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1490 if (scope != NULL && scope->se_type == BLOCK_SCOPE)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1491 compile_endblock(cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1492 scope = cctx->ctx_scope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1493
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1494 // Error if not in a :try scope
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1495 if (scope == NULL || scope->se_type != TRY_SCOPE)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1496 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26857
diff changeset
1497 emsg(_(e_finally_without_try));
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1498 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1499 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1500
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1501 if (cctx->ctx_skip != SKIP_YES)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1502 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1503 // End :catch or :finally scope: set value in ISN_TRY instruction
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1504 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_try_label;
26672
3516017e5f54 patch 8.2.3865: Vim9: compiler complains about using "try" as a struct member
Bram Moolenaar <Bram@vim.org>
parents: 26662
diff changeset
1505 if (isn->isn_arg.tryref.try_ref->try_finally != 0)
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1506 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26857
diff changeset
1507 emsg(_(e_multiple_finally));
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1511 this_instr = instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1512 #ifdef FEAT_PROFILE
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513 if (cctx->ctx_compile_type == CT_PROFILE
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1514 && ((isn_T *)instr->ga_data)[this_instr - 1]
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1515 .isn_type == ISN_PROF_START)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1516 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1517 // jump to the profile start of the "finally"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1518 --this_instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1519
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1520 // jump to the profile end above it
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521 if (this_instr > 0 && ((isn_T *)instr->ga_data)[this_instr - 1]
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 .isn_type == ISN_PROF_END)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1523 --this_instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1524 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1525 #endif
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1527 // Fill in the "end" label in jumps at the end of the blocks.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1528 compile_fill_jump_to_end(&scope->se_u.se_try.ts_end_label,
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1529 this_instr, cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1530
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1531 // If there is no :catch then an exception jumps to :finally.
26672
3516017e5f54 patch 8.2.3865: Vim9: compiler complains about using "try" as a struct member
Bram Moolenaar <Bram@vim.org>
parents: 26662
diff changeset
1532 if (isn->isn_arg.tryref.try_ref->try_catch == 0)
3516017e5f54 patch 8.2.3865: Vim9: compiler complains about using "try" as a struct member
Bram Moolenaar <Bram@vim.org>
parents: 26662
diff changeset
1533 isn->isn_arg.tryref.try_ref->try_catch = this_instr;
3516017e5f54 patch 8.2.3865: Vim9: compiler complains about using "try" as a struct member
Bram Moolenaar <Bram@vim.org>
parents: 26662
diff changeset
1534 isn->isn_arg.tryref.try_ref->try_finally = this_instr;
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1535 if (scope->se_u.se_try.ts_catch_label != 0)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1536 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537 // Previous catch without match jumps here
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_catch_label;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1539 isn->isn_arg.jump.jump_where = this_instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540 scope->se_u.se_try.ts_catch_label = 0;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1541 }
27084
6fc63c6a7ee7 patch 8.2.4071: Vim9: no detection of return in try/endtry
Bram Moolenaar <Bram@vim.org>
parents: 26984
diff changeset
1542 scope->se_u.se_try.ts_has_finally = TRUE;
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1543 if (generate_instr(cctx, ISN_FINALLY) == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1544 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1545 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1546
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547 return arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1548 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1549
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551 compile_endtry(char_u *arg, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1553 scope_T *scope = cctx->ctx_scope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554 garray_T *instr = &cctx->ctx_instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555 isn_T *try_isn;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1556
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1557 if (misplaced_cmdmod(cctx))
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1560 // end block scope from :catch or :finally
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1561 if (scope != NULL && scope->se_type == BLOCK_SCOPE)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562 compile_endblock(cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1563 scope = cctx->ctx_scope;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1564
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1565 // Error if not in a :try scope
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1566 if (scope == NULL || scope->se_type != TRY_SCOPE)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1567 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1568 if (scope == NULL)
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26857
diff changeset
1569 emsg(_(e_endtry_without_try));
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1570 else if (scope->se_type == WHILE_SCOPE)
26857
2aeea8611342 patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26771
diff changeset
1571 emsg(_(e_missing_endwhile));
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1572 else if (scope->se_type == FOR_SCOPE)
26857
2aeea8611342 patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26771
diff changeset
1573 emsg(_(e_missing_endfor));
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574 else
26857
2aeea8611342 patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26771
diff changeset
1575 emsg(_(e_missing_endif));
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1577 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1578
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1579 try_isn = ((isn_T *)instr->ga_data) + scope->se_u.se_try.ts_try_label;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1580 if (cctx->ctx_skip != SKIP_YES)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581 {
26672
3516017e5f54 patch 8.2.3865: Vim9: compiler complains about using "try" as a struct member
Bram Moolenaar <Bram@vim.org>
parents: 26662
diff changeset
1582 if (try_isn->isn_arg.tryref.try_ref->try_catch == 0
3516017e5f54 patch 8.2.3865: Vim9: compiler complains about using "try" as a struct member
Bram Moolenaar <Bram@vim.org>
parents: 26662
diff changeset
1583 && try_isn->isn_arg.tryref.try_ref->try_finally == 0)
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1584 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1585 emsg(_(e_missing_catch_or_finally));
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1586 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1587 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1588
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1589 #ifdef FEAT_PROFILE
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1590 if (cctx->ctx_compile_type == CT_PROFILE
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1591 && ((isn_T *)instr->ga_data)[instr->ga_len - 1]
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1592 .isn_type == ISN_PROF_START)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1593 // move the profile start after "endtry" so that it's not counted when
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1594 // the exception is rethrown.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1595 --instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1596 #endif
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1597
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1598 // Fill in the "end" label in jumps at the end of the blocks, if not
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1599 // done by ":finally".
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1600 compile_fill_jump_to_end(&scope->se_u.se_try.ts_end_label,
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1601 instr->ga_len, cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1602
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1603 if (scope->se_u.se_try.ts_catch_label != 0)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1604 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1605 // Last catch without match jumps here
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1606 isn_T *isn = ((isn_T *)instr->ga_data)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1607 + scope->se_u.se_try.ts_catch_label;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1608 isn->isn_arg.jump.jump_where = instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1609 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1610 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1611
27084
6fc63c6a7ee7 patch 8.2.4071: Vim9: no detection of return in try/endtry
Bram Moolenaar <Bram@vim.org>
parents: 26984
diff changeset
1612 // If there is a finally clause that ends in return then we will return.
6fc63c6a7ee7 patch 8.2.4071: Vim9: no detection of return in try/endtry
Bram Moolenaar <Bram@vim.org>
parents: 26984
diff changeset
1613 // If one of the blocks didn't end in "return" or we did not catch all
6fc63c6a7ee7 patch 8.2.4071: Vim9: no detection of return in try/endtry
Bram Moolenaar <Bram@vim.org>
parents: 26984
diff changeset
1614 // exceptions reset the had_return flag.
6fc63c6a7ee7 patch 8.2.4071: Vim9: no detection of return in try/endtry
Bram Moolenaar <Bram@vim.org>
parents: 26984
diff changeset
1615 if (!(scope->se_u.se_try.ts_has_finally && cctx->ctx_had_return)
6fc63c6a7ee7 patch 8.2.4071: Vim9: no detection of return in try/endtry
Bram Moolenaar <Bram@vim.org>
parents: 26984
diff changeset
1616 && (scope->se_u.se_try.ts_no_return
6fc63c6a7ee7 patch 8.2.4071: Vim9: no detection of return in try/endtry
Bram Moolenaar <Bram@vim.org>
parents: 26984
diff changeset
1617 || !scope->se_u.se_try.ts_caught_all))
6fc63c6a7ee7 patch 8.2.4071: Vim9: no detection of return in try/endtry
Bram Moolenaar <Bram@vim.org>
parents: 26984
diff changeset
1618 cctx->ctx_had_return = FALSE;
6fc63c6a7ee7 patch 8.2.4071: Vim9: no detection of return in try/endtry
Bram Moolenaar <Bram@vim.org>
parents: 26984
diff changeset
1619
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1620 compile_endblock(cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1621
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1622 if (cctx->ctx_skip != SKIP_YES)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1623 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1624 // End :catch or :finally scope: set instruction index in ISN_TRY
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1625 // instruction
26672
3516017e5f54 patch 8.2.3865: Vim9: compiler complains about using "try" as a struct member
Bram Moolenaar <Bram@vim.org>
parents: 26662
diff changeset
1626 try_isn->isn_arg.tryref.try_ref->try_endtry = instr->ga_len;
28169
bef82285dda0 patch 8.2.4610: some conditions are always true
Bram Moolenaar <Bram@vim.org>
parents: 28095
diff changeset
1627 if (generate_instr(cctx, ISN_ENDTRY) == NULL)
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1628 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1629 #ifdef FEAT_PROFILE
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1630 if (cctx->ctx_compile_type == CT_PROFILE)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1631 generate_instr(cctx, ISN_PROF_START);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1632 #endif
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1633 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1634 return arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1635 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1636
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1637 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1638 * compile "throw {expr}"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1639 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1640 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1641 compile_throw(char_u *arg, cctx_T *cctx UNUSED)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1642 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1643 char_u *p = skipwhite(arg);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1644
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1645 if (compile_expr0(&p, cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1646 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1647 if (cctx->ctx_skip == SKIP_YES)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1648 return p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1649 if (may_generate_2STRING(-1, FALSE, cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1651 if (generate_instr_drop(cctx, ISN_THROW, 1) == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1652 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1653
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1654 return p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1655 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1656
30065
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1657 /*
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1658 * Compile an expression or function call.
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1659 */
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1660 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1661 compile_eval(char_u *arg, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1662 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1663 char_u *p = arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1664 int name_only;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1665 long lnum = SOURCING_LNUM;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1666
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1667 // find_ex_command() will consider a variable name an expression, assuming
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1668 // that something follows on the next line. Check that something actually
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669 // follows, otherwise it's probably a misplaced command.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1670 name_only = cmd_is_name_only(arg);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1671
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1672 if (compile_expr0(&p, cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1674
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 if (name_only && lnum == SOURCING_LNUM)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1676 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677 semsg(_(e_expression_without_effect_str), arg);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1678 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1679 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1680
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1681 // drop the result
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1682 generate_instr_drop(cctx, ISN_DROP, 1);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1683
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684 return skipwhite(p);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1685 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1686
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1687 /*
30065
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1688 * Compile "defer func(arg)".
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1689 */
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1690 char_u *
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1691 compile_defer(char_u *arg_start, cctx_T *cctx)
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1692 {
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1693 char_u *p;
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1694 char_u *arg = arg_start;
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1695 int argcount = 0;
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1696 dfunc_T *dfunc;
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1697 type_T *type;
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1698 int func_idx;
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1699
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1700 // Get a funcref for the function name.
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1701 // TODO: better way to find the "(".
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1702 p = vim_strchr(arg, '(');
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1703 if (p == NULL)
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1704 {
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1705 semsg(_(e_missing_parenthesis_str), arg);
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1706 return NULL;
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1707 }
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1708 *p = NUL;
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1709 func_idx = find_internal_func(arg);
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1710 if (func_idx >= 0)
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1711 // TODO: better type
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1712 generate_PUSHFUNC(cctx, (char_u *)internal_func_name(func_idx),
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1713 &t_func_any, FALSE);
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1714 else if (compile_expr0(&arg, cctx) == FAIL)
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1715 return NULL;
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1716 *p = '(';
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1717
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1718 // check for function type
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1719 type = get_type_on_stack(cctx, 0);
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1720 if (type->tt_type != VAR_FUNC)
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1721 {
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1722 emsg(_(e_function_name_required));
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1723 return NULL;
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1724 }
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1725
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1726 // compile the arguments
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1727 arg = skipwhite(p + 1);
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1728 if (compile_arguments(&arg, cctx, &argcount, CA_NOT_SPECIAL) == FAIL)
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1729 return NULL;
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1730
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1731 // TODO: check argument count with "type"
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1732
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1733 dfunc = ((dfunc_T *)def_functions.ga_data) + cctx->ctx_ufunc->uf_dfunc_idx;
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1734 if (dfunc->df_defer_var_idx == 0)
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1735 {
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1736 lvar_T *lvar = reserve_local(cctx, (char_u *)"@defer@", 7,
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1737 TRUE, &t_list_any);
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1738 if (lvar == NULL)
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1739 return NULL;
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1740 dfunc->df_defer_var_idx = lvar->lv_idx + 1;
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1741 }
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1742 if (generate_DEFER(cctx, dfunc->df_defer_var_idx - 1, argcount) == FAIL)
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1743 return NULL;
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1744
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1745 return skipwhite(arg);
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1746 }
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1747
6cf788ab844c patch 9.0.0370: cleaning up afterwards can make a function messy
Bram Moolenaar <Bram@vim.org>
parents: 30025
diff changeset
1748 /*
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1749 * compile "echo expr"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1750 * compile "echomsg expr"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1751 * compile "echoerr expr"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1752 * compile "echoconsole expr"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1753 * compile "execute expr"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1754 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1755 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1756 compile_mult_expr(char_u *arg, int cmdidx, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1757 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1758 char_u *p = arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1759 char_u *prev = arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1760 char_u *expr_start;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1761 int count = 0;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1762 int start_ctx_lnum = cctx->ctx_lnum;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1763 type_T *type;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1764
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1765 for (;;)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1766 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1767 if (ends_excmd2(prev, p))
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1768 break;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1769 expr_start = p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1770 if (compile_expr0(&p, cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1771 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1772
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1773 if (cctx->ctx_skip != SKIP_YES)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1774 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1775 // check for non-void type
26935
ccb9be1cdd71 patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents: 26905
diff changeset
1776 type = get_type_on_stack(cctx, 0);
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1777 if (type->tt_type == VAR_VOID)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1778 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1779 semsg(_(e_expression_does_not_result_in_value_str), expr_start);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1780 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1781 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1782 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1783
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1784 ++count;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1785 prev = p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1786 p = skipwhite(p);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1787 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1788
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1789 if (count > 0)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1790 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1791 long save_lnum = cctx->ctx_lnum;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1792
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1793 // Use the line number where the command started.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1794 cctx->ctx_lnum = start_ctx_lnum;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1795
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1796 if (cmdidx == CMD_echo || cmdidx == CMD_echon)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1797 generate_ECHO(cctx, cmdidx == CMD_echo, count);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1798 else if (cmdidx == CMD_execute)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1799 generate_MULT_EXPR(cctx, ISN_EXECUTE, count);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1800 else if (cmdidx == CMD_echomsg)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1801 generate_MULT_EXPR(cctx, ISN_ECHOMSG, count);
30025
d269dd3cd31d patch 9.0.0350: :echowindow does not work in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 29744
diff changeset
1802 #ifdef HAS_MESSAGE_WINDOW
d269dd3cd31d patch 9.0.0350: :echowindow does not work in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 29744
diff changeset
1803 else if (cmdidx == CMD_echowindow)
d269dd3cd31d patch 9.0.0350: :echowindow does not work in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 29744
diff changeset
1804 generate_MULT_EXPR(cctx, ISN_ECHOWINDOW, count);
d269dd3cd31d patch 9.0.0350: :echowindow does not work in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 29744
diff changeset
1805 #endif
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1806 else if (cmdidx == CMD_echoconsole)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1807 generate_MULT_EXPR(cctx, ISN_ECHOCONSOLE, count);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1808 else
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1809 generate_MULT_EXPR(cctx, ISN_ECHOERR, count);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1810
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1811 cctx->ctx_lnum = save_lnum;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1812 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1813 return p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1814 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1815
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1816 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1817 * If "eap" has a range that is not a constant generate an ISN_RANGE
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1818 * instruction to compute it and return OK.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1819 * Otherwise return FAIL, the caller must deal with any range.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1820 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1821 static int
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1822 compile_variable_range(exarg_T *eap, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1823 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1824 char_u *range_end = skip_range(eap->cmd, TRUE, NULL);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1825 char_u *p = skipdigits(eap->cmd);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1826
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1827 if (p == range_end)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1828 return FAIL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1829 return generate_RANGE(cctx, vim_strnsave(eap->cmd, range_end - eap->cmd));
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1830 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1831
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1832 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1833 * :put r
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1834 * :put ={expr}
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1835 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1836 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1837 compile_put(char_u *arg, exarg_T *eap, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1838 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1839 char_u *line = arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1840 linenr_T lnum;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1841 char *errormsg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1842 int above = eap->forceit;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1843
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1844 eap->regname = *line;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1845
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1846 if (eap->regname == '=')
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1847 {
28055
5bf3ed75e26c patch 8.2.4552: in a :def function "put = expr" does not work
Bram Moolenaar <Bram@vim.org>
parents: 28035
diff changeset
1848 char_u *p = skipwhite(line + 1);
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1849
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1850 if (compile_expr0(&p, cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1851 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1852 line = p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1853 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1854 else if (eap->regname != NUL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1855 ++line;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1856
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1857 if (compile_variable_range(eap, cctx) == OK)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1858 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1859 lnum = above ? LNUM_VARIABLE_RANGE_ABOVE : LNUM_VARIABLE_RANGE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1860 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1861 else
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1862 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1863 // Either no range or a number.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1864 // "errormsg" will not be set because the range is ADDR_LINES.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1865 if (parse_cmd_address(eap, &errormsg, FALSE) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1866 // cannot happen
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1867 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1868 if (eap->addr_count == 0)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1869 lnum = -1;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1870 else
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1871 lnum = eap->line2;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1872 if (above)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1873 --lnum;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1874 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1875
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1876 generate_PUT(cctx, eap->regname, lnum);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1877 return line;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1878 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1879
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1880 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1881 * A command that is not compiled, execute with legacy code.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1882 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1883 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1884 compile_exec(char_u *line_arg, exarg_T *eap, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1885 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1886 char_u *line = line_arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1887 char_u *p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1888 int has_expr = FALSE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1889 char_u *nextcmd = (char_u *)"";
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1890 char_u *tofree = NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1891 char_u *cmd_arg = NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1892
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1893 if (cctx->ctx_skip == SKIP_YES)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1894 goto theend;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1895
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1896 // If there was a prececing command modifier, drop it and include it in the
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1897 // EXEC command.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1898 if (cctx->ctx_has_cmdmod)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1899 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1900 garray_T *instr = &cctx->ctx_instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1901 isn_T *isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1902
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1903 if (isn->isn_type == ISN_CMDMOD)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1904 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1905 vim_regfree(isn->isn_arg.cmdmod.cf_cmdmod
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1906 ->cmod_filter_regmatch.regprog);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1907 vim_free(isn->isn_arg.cmdmod.cf_cmdmod);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1908 --instr->ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1909 cctx->ctx_has_cmdmod = FALSE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1910 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1911 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1912
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1913 if (eap->cmdidx >= 0 && eap->cmdidx < CMD_SIZE)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1914 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1915 long argt = eap->argt;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1916 int usefilter = FALSE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1917
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1918 has_expr = argt & (EX_XFILE | EX_EXPAND);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1919
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1920 // If the command can be followed by a bar, find the bar and truncate
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1921 // it, so that the following command can be compiled.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1922 // The '|' is overwritten with a NUL, it is put back below.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1923 if ((eap->cmdidx == CMD_write || eap->cmdidx == CMD_read)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1924 && *eap->arg == '!')
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1925 // :w !filter or :r !filter or :r! filter
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1926 usefilter = TRUE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1927 if ((argt & EX_TRLBAR) && !usefilter)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1928 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1929 eap->argt = argt;
28179
49631bf057d3 patch 8.2.4615: mapping with escaped bar does not work in :def function
Bram Moolenaar <Bram@vim.org>
parents: 28169
diff changeset
1930 separate_nextcmd(eap, TRUE);
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1931 if (eap->nextcmd != NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1932 nextcmd = eap->nextcmd;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1933 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1934 else if (eap->cmdidx == CMD_wincmd)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1935 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1936 p = eap->arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1937 if (*p != NUL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1938 ++p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1939 if (*p == 'g' || *p == Ctrl_G)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1940 ++p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1941 p = skipwhite(p);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1942 if (*p == '|')
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1943 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1944 *p = NUL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1945 nextcmd = p + 1;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1946 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1947 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1948 else if (eap->cmdidx == CMD_command || eap->cmdidx == CMD_autocmd)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1949 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1950 // If there is a trailing '{' read lines until the '}'
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1951 p = eap->arg + STRLEN(eap->arg) - 1;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1952 while (p > eap->arg && VIM_ISWHITE(*p))
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1953 --p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1954 if (*p == '{')
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1955 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1956 exarg_T ea;
27891
6f5c8493a238 patch 8.2.4471: Coverity warns for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents: 27583
diff changeset
1957 int flags = 0; // unused
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958 int start_lnum = SOURCING_LNUM;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1959
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1960 CLEAR_FIELD(ea);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1961 ea.arg = eap->arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1962 fill_exarg_from_cctx(&ea, cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1963 (void)may_get_cmd_block(&ea, p, &tofree, &flags);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1964 if (tofree != NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1965 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1966 *p = NUL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1967 line = concat_str(line, tofree);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1968 if (line == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1969 goto theend;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1970 vim_free(tofree);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1971 tofree = line;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1972 SOURCING_LNUM = start_lnum;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1973 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1974 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1975 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1976 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1977
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1978 if (eap->cmdidx == CMD_syntax && STRNCMP(eap->arg, "include ", 8) == 0)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1979 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1980 // expand filename in "syntax include [@group] filename"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1981 has_expr = TRUE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1982 eap->arg = skipwhite(eap->arg + 7);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1983 if (*eap->arg == '@')
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1984 eap->arg = skiptowhite(eap->arg);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1985 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1986
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1987 if ((eap->cmdidx == CMD_global || eap->cmdidx == CMD_vglobal)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1988 && STRLEN(eap->arg) > 4)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1989 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1990 int delim = *eap->arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1991
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1992 p = skip_regexp_ex(eap->arg + 1, delim, TRUE, NULL, NULL, NULL);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1993 if (*p == delim)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1994 cmd_arg = p + 1;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1995 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1996
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1997 if (eap->cmdidx == CMD_folddoopen || eap->cmdidx == CMD_folddoclosed)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1998 cmd_arg = eap->arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1999
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2000 if (cmd_arg != NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2001 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2002 exarg_T nea;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2003
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2004 CLEAR_FIELD(nea);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2005 nea.cmd = cmd_arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2006 p = find_ex_command(&nea, NULL, lookup_scriptitem, NULL);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2007 if (nea.cmdidx < CMD_SIZE)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2008 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2009 has_expr = excmd_get_argt(nea.cmdidx) & (EX_XFILE | EX_EXPAND);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2010 if (has_expr)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2011 eap->arg = skiptowhite(eap->arg);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2012 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2013 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2014
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2015 if (has_expr && (p = (char_u *)strstr((char *)eap->arg, "`=")) != NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2016 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2017 int count = 0;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2018 char_u *start = skipwhite(line);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2019
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2020 // :cmd xxx`=expr1`yyy`=expr2`zzz
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2021 // PUSHS ":cmd xxx"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2022 // eval expr1
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2023 // PUSHS "yyy"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2024 // eval expr2
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2025 // PUSHS "zzz"
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2026 // EXECCONCAT 5
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2027 for (;;)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2028 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2029 if (p > start)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2030 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2031 char_u *val = vim_strnsave(start, p - start);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2032
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2033 generate_PUSHS(cctx, &val);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2034 ++count;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2035 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2036 p += 2;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2037 if (compile_expr0(&p, cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2038 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2039 may_generate_2STRING(-1, TRUE, cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2040 ++count;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2041 p = skipwhite(p);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2042 if (*p != '`')
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2043 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2044 emsg(_(e_missing_backtick));
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2045 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2046 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2047 start = p + 1;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2048
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2049 p = (char_u *)strstr((char *)start, "`=");
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2050 if (p == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2051 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2052 if (*skipwhite(start) != NUL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2053 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2054 char_u *val = vim_strsave(start);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2055
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2056 generate_PUSHS(cctx, &val);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2057 ++count;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2058 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2059 break;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2060 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2061 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2062 generate_EXECCONCAT(cctx, count);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2063 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2064 else
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2065 generate_EXEC_copy(cctx, ISN_EXEC, line);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2066
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2067 theend:
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2068 if (*nextcmd != NUL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2069 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2070 // the parser expects a pointer to the bar, put it back
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2071 --nextcmd;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2072 *nextcmd = '|';
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2073 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2074 vim_free(tofree);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2075
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2076 return nextcmd;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2077 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2078
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2079 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2080 * A script command with heredoc, e.g.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2081 * ruby << EOF
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2082 * command
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2083 * EOF
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2084 * Has been turned into one long line with NL characters by
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2085 * get_function_body():
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2086 * ruby << EOF<NL> command<NL>EOF
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2087 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2088 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2089 compile_script(char_u *line, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2090 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2091 if (cctx->ctx_skip != SKIP_YES)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2092 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2093 isn_T *isn;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2094
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2095 if ((isn = generate_instr(cctx, ISN_EXEC_SPLIT)) == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2096 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2097 isn->isn_arg.string = vim_strsave(line);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2098 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2099 return (char_u *)"";
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2100 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2101
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2102
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2103 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2104 * :s/pat/repl/
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2105 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2106 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2107 compile_substitute(char_u *arg, exarg_T *eap, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2108 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2109 char_u *cmd = eap->arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2110 char_u *expr = (char_u *)strstr((char *)cmd, "\\=");
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2111
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2112 if (expr != NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2113 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2114 int delimiter = *cmd++;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2115
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2116 // There is a \=expr, find it in the substitute part.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2117 cmd = skip_regexp_ex(cmd, delimiter, magic_isset(), NULL, NULL, NULL);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2118 if (cmd[0] == delimiter && cmd[1] == '\\' && cmd[2] == '=')
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2119 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2120 garray_T save_ga = cctx->ctx_instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2121 char_u *end;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2122 int expr_res;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2123 int trailing_error;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2124 int instr_count;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2125 isn_T *instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2126 isn_T *isn;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2127
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2128 cmd += 3;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2129 end = skip_substitute(cmd, delimiter);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2130
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2131 // Temporarily reset the list of instructions so that the jump
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2132 // labels are correct.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2133 cctx->ctx_instr.ga_len = 0;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2134 cctx->ctx_instr.ga_maxlen = 0;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2135 cctx->ctx_instr.ga_data = NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2136 expr_res = compile_expr0(&cmd, cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2137 if (end[-1] == NUL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2138 end[-1] = delimiter;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2139 cmd = skipwhite(cmd);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2140 trailing_error = *cmd != delimiter && *cmd != NUL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2141
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2142 if (expr_res == FAIL || trailing_error
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2143 || GA_GROW_FAILS(&cctx->ctx_instr, 1))
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2144 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2145 if (trailing_error)
26883
7f150a4936f2 patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
2146 semsg(_(e_trailing_characters_str), cmd);
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2147 clear_instr_ga(&cctx->ctx_instr);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2148 cctx->ctx_instr = save_ga;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2149 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2150 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2151
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2152 // Move the generated instructions into the ISN_SUBSTITUTE
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2153 // instructions, then restore the list of instructions before
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2154 // adding the ISN_SUBSTITUTE instruction.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2155 instr_count = cctx->ctx_instr.ga_len;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2156 instr = cctx->ctx_instr.ga_data;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2157 instr[instr_count].isn_type = ISN_FINISH;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2158
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2159 cctx->ctx_instr = save_ga;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2160 if ((isn = generate_instr(cctx, ISN_SUBSTITUTE)) == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2161 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2162 int idx;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2163
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2164 for (idx = 0; idx < instr_count; ++idx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2165 delete_instr(instr + idx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2166 vim_free(instr);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2167 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2168 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2169 isn->isn_arg.subs.subs_cmd = vim_strsave(arg);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2170 isn->isn_arg.subs.subs_instr = instr;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2171
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2172 // skip over flags
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2173 if (*end == '&')
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2174 ++end;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2175 while (ASCII_ISALPHA(*end) || *end == '#')
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2176 ++end;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2177 return end;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2178 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2179 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2180
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2181 return compile_exec(arg, eap, cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2182 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2183
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2184 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2185 compile_redir(char_u *line, exarg_T *eap, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2186 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2187 char_u *arg = eap->arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2188 lhs_T *lhs = &cctx->ctx_redir_lhs;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2189
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2190 if (lhs->lhs_name != NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2191 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2192 if (STRNCMP(arg, "END", 3) == 0)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2193 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2194 if (lhs->lhs_append)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2195 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2196 // First load the current variable value.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2197 if (compile_load_lhs_with_index(lhs, lhs->lhs_whole,
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2198 cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2199 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2200 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2201
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2202 // Gets the redirected text and put it on the stack, then store it
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2203 // in the variable.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2204 generate_instr_type(cctx, ISN_REDIREND, &t_string);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2205
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2206 if (lhs->lhs_append)
28598
d550054e1328 patch 8.2.4823: concat more than 2 strings in :def function is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 28281
diff changeset
2207 generate_CONCAT(cctx, 2);
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2208
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2209 if (lhs->lhs_has_index)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2210 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2211 // Use the info in "lhs" to store the value at the index in the
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2212 // list or dict.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2213 if (compile_assign_unlet(lhs->lhs_whole, lhs, TRUE,
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2214 &t_string, cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2215 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2216 }
26729
b969fdb8cd46 patch 8.2.3893: Vim9: many local variables are initialized with an instruction
Bram Moolenaar <Bram@vim.org>
parents: 26674
diff changeset
2217 else if (generate_store_lhs(cctx, lhs, -1, FALSE) == FAIL)
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2218 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2219
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2220 VIM_CLEAR(lhs->lhs_name);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2221 VIM_CLEAR(lhs->lhs_whole);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2222 return arg + 3;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2223 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2224 emsg(_(e_cannot_nest_redir));
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2225 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2226 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2227
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2228 if (arg[0] == '=' && arg[1] == '>')
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2229 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2230 int append = FALSE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2231
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2232 // redirect to a variable is compiled
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2233 arg += 2;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2234 if (*arg == '>')
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2235 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2236 ++arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2237 append = TRUE;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2238 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2239 arg = skipwhite(arg);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2240
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2241 if (compile_assign_lhs(arg, lhs, CMD_redir,
28281
bd1dcc605e58 patch 8.2.4666: Vim9: assignment not recognized in skipped block
Bram Moolenaar <Bram@vim.org>
parents: 28179
diff changeset
2242 FALSE, FALSE, FALSE, 1, cctx) == FAIL)
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2243 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2244 if (need_type(&t_string, lhs->lhs_member_type,
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2245 -1, 0, cctx, FALSE, FALSE) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2246 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2247 generate_instr(cctx, ISN_REDIRSTART);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2248 lhs->lhs_append = append;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2249 if (lhs->lhs_has_index)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2250 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2251 lhs->lhs_whole = vim_strnsave(arg, lhs->lhs_varlen_total);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2252 if (lhs->lhs_whole == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2253 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2254 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2255
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2256 return arg + lhs->lhs_varlen_total;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2257 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2258
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2259 // other redirects are handled like at script level
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2260 return compile_exec(line, eap, cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2261 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2262
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2263 #if defined(FEAT_QUICKFIX) || defined(PROTO)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2264 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2265 compile_cexpr(char_u *line, exarg_T *eap, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2266 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2267 isn_T *isn;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2268 char_u *p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2269
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2270 isn = generate_instr(cctx, ISN_CEXPR_AUCMD);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2271 if (isn == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2272 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2273 isn->isn_arg.number = eap->cmdidx;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2274
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2275 p = eap->arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2276 if (compile_expr0(&p, cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2277 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2278
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2279 isn = generate_instr(cctx, ISN_CEXPR_CORE);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2280 if (isn == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2281 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2282 isn->isn_arg.cexpr.cexpr_ref = ALLOC_ONE(cexprref_T);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2283 if (isn->isn_arg.cexpr.cexpr_ref == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2284 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2285 isn->isn_arg.cexpr.cexpr_ref->cer_cmdidx = eap->cmdidx;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2286 isn->isn_arg.cexpr.cexpr_ref->cer_forceit = eap->forceit;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2287 isn->isn_arg.cexpr.cexpr_ref->cer_cmdline = vim_strsave(skipwhite(line));
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2288
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2289 return p;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2290 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2291 #endif
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2292
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2293 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2294 * Compile "return [expr]".
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2295 * When "legacy" is TRUE evaluate [expr] with legacy syntax
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2296 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2297 char_u *
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2298 compile_return(char_u *arg, int check_return_type, int legacy, cctx_T *cctx)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2299 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2300 char_u *p = arg;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2301 type_T *stack_type;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2302
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2303 if (*p != NUL && *p != '|' && *p != '\n')
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2304 {
27299
7218ad7a55d2 patch 8.2.4178: Vim9: invalid error for return type of lambda when debugging
Bram Moolenaar <Bram@vim.org>
parents: 27219
diff changeset
2305 // For a lambda, "return expr" is always used, also when "expr" results
7218ad7a55d2 patch 8.2.4178: Vim9: invalid error for return type of lambda when debugging
Bram Moolenaar <Bram@vim.org>
parents: 27219
diff changeset
2306 // in a void.
7218ad7a55d2 patch 8.2.4178: Vim9: invalid error for return type of lambda when debugging
Bram Moolenaar <Bram@vim.org>
parents: 27219
diff changeset
2307 if (cctx->ctx_ufunc->uf_ret_type->tt_type == VAR_VOID
7218ad7a55d2 patch 8.2.4178: Vim9: invalid error for return type of lambda when debugging
Bram Moolenaar <Bram@vim.org>
parents: 27219
diff changeset
2308 && (cctx->ctx_ufunc->uf_flags & FC_LAMBDA) == 0)
27219
47dbeda35910 patch 8.2.4138: Vim9: no error for return with argument when invalid
Bram Moolenaar <Bram@vim.org>
parents: 27084
diff changeset
2309 {
47dbeda35910 patch 8.2.4138: Vim9: no error for return with argument when invalid
Bram Moolenaar <Bram@vim.org>
parents: 27084
diff changeset
2310 emsg(_(e_returning_value_in_function_without_return_type));
47dbeda35910 patch 8.2.4138: Vim9: no error for return with argument when invalid
Bram Moolenaar <Bram@vim.org>
parents: 27084
diff changeset
2311 return NULL;
47dbeda35910 patch 8.2.4138: Vim9: no error for return with argument when invalid
Bram Moolenaar <Bram@vim.org>
parents: 27084
diff changeset
2312 }
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2313 if (legacy)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2314 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2315 int save_flags = cmdmod.cmod_flags;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2316
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2317 generate_LEGACY_EVAL(cctx, p);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2318 if (need_type(&t_any, cctx->ctx_ufunc->uf_ret_type, -1,
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2319 0, cctx, FALSE, FALSE) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2320 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2321 cmdmod.cmod_flags |= CMOD_LEGACY;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2322 (void)skip_expr(&p, NULL);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2323 cmdmod.cmod_flags = save_flags;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2324 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2325 else
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2326 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2327 // compile return argument into instructions
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2328 if (compile_expr0(&p, cctx) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2329 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2330 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2331
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2332 if (cctx->ctx_skip != SKIP_YES)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2333 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2334 // "check_return_type" with uf_ret_type set to &t_unknown is used
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2335 // for an inline function without a specified return type. Set the
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2336 // return type here.
26935
ccb9be1cdd71 patch 8.2.3996: Vim9: type checking lacks information about declared type
Bram Moolenaar <Bram@vim.org>
parents: 26905
diff changeset
2337 stack_type = get_type_on_stack(cctx, 0);
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2338 if ((check_return_type && (cctx->ctx_ufunc->uf_ret_type == NULL
28095
8a80c48bd103 patch 8.2.4572: Vim9: return type "any" is changed to first returned type
Bram Moolenaar <Bram@vim.org>
parents: 28055
diff changeset
2339 || cctx->ctx_ufunc->uf_ret_type == &t_unknown))
26662
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2340 || (!check_return_type
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2341 && cctx->ctx_ufunc->uf_ret_type == &t_unknown))
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2342 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2343 cctx->ctx_ufunc->uf_ret_type = stack_type;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2344 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2345 else
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2346 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2347 if (need_type(stack_type, cctx->ctx_ufunc->uf_ret_type, -1,
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2348 0, cctx, FALSE, FALSE) == FAIL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2349 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2350 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2351 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2352 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2353 else
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2354 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2355 // "check_return_type" cannot be TRUE, only used for a lambda which
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2356 // always has an argument.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2357 if (cctx->ctx_ufunc->uf_ret_type->tt_type != VAR_VOID
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2358 && cctx->ctx_ufunc->uf_ret_type->tt_type != VAR_UNKNOWN)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2359 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2360 emsg(_(e_missing_return_value));
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2361 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2362 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2363
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2364 // No argument, return zero.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2365 generate_PUSHNR(cctx, 0);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2366 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2367
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2368 // Undo any command modifiers.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2369 generate_undo_cmdmods(cctx);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2370
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2371 if (cctx->ctx_skip != SKIP_YES && generate_instr(cctx, ISN_RETURN) == NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2372 return NULL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2373
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2374 // "return val | endif" is possible
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2375 return skipwhite(p);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2376 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2377
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2378 /*
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2379 * Check if the separator for a :global or :substitute command is OK.
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2380 */
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2381 int
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2382 check_global_and_subst(char_u *cmd, char_u *arg)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2383 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2384 if (arg == cmd + 1 && vim_strchr((char_u *)":-.", *arg) != NULL)
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2385 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2386 semsg(_(e_separator_not_supported_str), arg);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2387 return FAIL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2388 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2389 if (VIM_ISWHITE(cmd[1]))
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2390 {
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2391 semsg(_(e_no_white_space_allowed_before_separator_str), cmd);
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2392 return FAIL;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2393 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2394 return OK;
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2395 }
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2396
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2397
4b23672d1f0e patch 8.2.3860: Vim9: codecov struggles with the file size
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2398 #endif // defined(FEAT_EVAL)